Compare commits

..

2 Commits

Author SHA1 Message Date
pavlov%netscape.com
c45c2db17b new shit
git-svn-id: svn://10.0.0.236/branches/IMGLIB2_NEW@91713 18797224-902f-48f8-a5cc-f745e15eee43
2001-04-08 23:55:33 +00:00
(no author)
ebc0074860 This commit was manufactured by cvs2svn to create branch 'IMGLIB2_NEW'.
git-svn-id: svn://10.0.0.236/branches/IMGLIB2_NEW@91429 18797224-902f-48f8-a5cc-f745e15eee43
2001-04-05 06:02:33 +00:00
115 changed files with 10309 additions and 6162 deletions

View File

@@ -1,12 +0,0 @@
// stdafx.cpp : source file that includes just the standard includes
// stdafx.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
#ifdef _ATL_STATIC_REGISTRY
#include <statreg.h>
#include <statreg.cpp>
#endif
#include <atlimpl.cpp>

View File

@@ -1,28 +0,0 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#if !defined(AFX_STDAFX_H__3B3A8A37_A147_4D96_BFA3_51B0F69B5D8D__INCLUDED_)
#define AFX_STDAFX_H__3B3A8A37_A147_4D96_BFA3_51B0F69B5D8D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define STRICT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#define _ATL_APARTMENT_THREADED
#include <atlbase.h>
//You may derive a class from CComModule and use it if you want to override
//something, but do not change the name of _Module
extern CComModule _Module;
#include <atlcom.h>
#include <comdef.h>
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__3B3A8A37_A147_4D96_BFA3_51B0F69B5D8D__INCLUDED)

View File

@@ -1,28 +0,0 @@
#ifndef XPCDispUtilities_h
#define XPCDispUtilities_h
template <class T>
inline
HRESULT XPCCreateInstance(const CLSID & clsid, const IID & iid, T ** result)
{
return CoCreateInstance(clsid, 0, CLSCTX_ALL, iid, reinterpret_cast<void**>(result));
}
DISPID GetIDsOfNames(IDispatch * pIDispatch , CComBSTR const & name)
{
DISPID dispid;
OLECHAR * pName = name;
HRESULT hresult = pIDispatch->GetIDsOfNames(
IID_NULL,
&pName,
1,
LOCALE_SYSTEM_DEFAULT,
&dispid);
if (!SUCCEEDED(hresult))
{
dispid = 0;
}
return dispid;
}
#endif

View File

@@ -1,86 +0,0 @@
// XPCIDispatchTest.cpp : Implementation of DLL Exports.
// Note: Proxy/Stub Information
// To build a separate proxy/stub DLL,
// run nmake -f IDispatchTestps.mk in the project directory.
#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "XPCIDispatchTest.h"
#include "XPCIDispatchTest_i.c"
#include "nsXPCDispTestMethods.h"
#include "nsXPCDispSimple.h"
#include "nsXPCDispTestNoIDispatch.h"
#include "nsXPCDispTestProperties.h"
#include "nsXPCDispTestArrays.h"
#include "nsXPCDispTestScriptOn.h"
#include "nsXPCDispTestScriptOff.h"
#include "nsXPCDispTestWrappedJS.h"
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_nsXPCDispTestMethods, nsXPCDispTestMethods)
OBJECT_ENTRY(CLSID_nsXPCDispSimple, nsXPCDispSimple)
OBJECT_ENTRY(CLSID_nsXPCDispTestNoIDispatch, nsXPCDispTestNoIDispatch)
OBJECT_ENTRY(CLSID_nsXPCDispTestProperties, nsXPCDispTestProperties)
OBJECT_ENTRY(CLSID_nsXPCDispTestArrays, nsXPCDispTestArrays)
OBJECT_ENTRY(CLSID_nsXPCDispTestScriptOn, nsXPCDispTestScriptOn)
OBJECT_ENTRY(CLSID_nsXPCDispTestScriptOff, nsXPCDispTestScriptOff)
OBJECT_ENTRY(CLSID_nsXPCDispTestWrappedJS, nsXPCDispTestWrappedJS)
END_OBJECT_MAP()
/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
_Module.Init(ObjectMap, hInstance, &LIBID_IDispatchTestLib);
DisableThreadLibraryCalls(hInstance);
}
else if (dwReason == DLL_PROCESS_DETACH)
_Module.Term();
return TRUE; // ok
}
/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
return _Module.GetClassObject(rclsid, riid, ppv);
}
/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
// registers object, typelib and all interfaces in typelib
return _Module.RegisterServer(TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
return _Module.UnregisterServer(TRUE);
}
#include "nsXPCDispTestWrappedJS.h"

View File

@@ -1,9 +0,0 @@
; XPCIDispatchTest.def : Declares the module parameters.
LIBRARY "XPCIDispatchTest.DLL"
EXPORTS
DllCanUnloadNow @1 PRIVATE
DllGetClassObject @2 PRIVATE
DllRegisterServer @3 PRIVATE
DllUnregisterServer @4 PRIVATE

View File

@@ -1,318 +0,0 @@
# Microsoft Developer Studio Project File - Name="XPCIDispatchTest" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=XPCIDispatchTest - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "XPCIDispatchTest.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "XPCIDispatchTest.mak" CFG="XPCIDispatchTest - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "XPCIDispatchTest - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "XPCIDispatchTest - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "XPCIDispatchTest - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
# Begin Custom Build - Performing registration
OutDir=.\Debug
TargetPath=.\Debug\XPCIDispatchTest.dll
InputPath=.\Debug\XPCIDispatchTest.dll
SOURCE="$(InputPath)"
"$(OutDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
regsvr32 /s /c "$(TargetPath)"
echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg"
# End Custom Build
!ELSEIF "$(CFG)" == "XPCIDispatchTest - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "XPCIDispatchTest___Win32_Release"
# PROP BASE Intermediate_Dir "XPCIDispatchTest___Win32_Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "_ATL_DLL" /D "_ATL_MIN_CRT" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "_ATL_DLL" /D "_ATL_MIN_CRT" /Yu"stdafx.h" /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
# Begin Custom Build - Performing registration
OutDir=.\Release
TargetPath=.\Release\XPCIDispatchTest.dll
InputPath=.\Release\XPCIDispatchTest.dll
SOURCE="$(InputPath)"
"$(OutDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
regsvr32 /s /c "$(TargetPath)"
echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg"
# End Custom Build
!ENDIF
# Begin Target
# Name "XPCIDispatchTest - Win32 Debug"
# Name "XPCIDispatchTest - Win32 Release"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\nsXPCDispSimple.cpp
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestArrays.cpp
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestMethods.cpp
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestNoIDispatch.cpp
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestProperties.cpp
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestScriptOff.cpp
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestScriptOn.cpp
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestWrappedJS.cpp
# End Source File
# Begin Source File
SOURCE=.\StdAfx.cpp
# ADD CPP /Yc"stdafx.h"
# End Source File
# Begin Source File
SOURCE=.\XPCIDispatchTest.cpp
# End Source File
# Begin Source File
SOURCE=.\XPCIDispatchTest.def
# End Source File
# Begin Source File
SOURCE=.\XPCIDispatchTest.idl
# ADD MTL /tlb ".\XPCIDispatchTest.tlb" /h "XPCIDispatchTest.h" /iid "XPCIDispatchTest_i.c" /Oicf
# End Source File
# Begin Source File
SOURCE=.\XPCIDispatchTest.rc
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\nsXPCDispSimple.h
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestArrays.h
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestMethods.h
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestNoIDispatch.h
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestProperties.h
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestScriptOff.h
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestScriptOn.h
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestWrappedJS.h
# End Source File
# Begin Source File
SOURCE=.\Resource.h
# End Source File
# Begin Source File
SOURCE=.\StdAfx.h
# End Source File
# Begin Source File
SOURCE=.\XPCDispUtilities.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\nsXPCDispSimple.rgs
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestArrays.rgs
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestMethods.rgs
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestNoIDispatch.rgs
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestNoScript.rgs
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestProperties.rgs
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestScriptOff.rgs
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestScriptOn.rgs
# End Source File
# Begin Source File
SOURCE=.\nsXPCDispTestWrappedJS.rgs
# End Source File
# End Group
# Begin Group "JS Files"
# PROP Default_Filter "js"
# Begin Group "WrappedCOM"
# PROP Default_Filter ""
# Begin Group "Arrays"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\Tests\WrappedCOM\Arrays\XPCIDispatchArrayTests.js
# End Source File
# End Group
# Begin Group "Attributes"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\Tests\WrappedCOM\Attributes\XPCIDispatchAttributeTests.js
# End Source File
# End Group
# Begin Group "General"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\Tests\WrappedCOM\General\XPCIDispatchInstantiations.js
# End Source File
# Begin Source File
SOURCE=..\Tests\WrappedCOM\General\XPCStress.js
# End Source File
# End Group
# Begin Group "Methods"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\Tests\WrappedCOM\Methods\XPCIDispatchMethodTests.js
# End Source File
# End Group
# Begin Source File
SOURCE=..\Tests\WrappedCOM\shell.js
# End Source File
# End Group
# Begin Group "WrappedJS"
# PROP Default_Filter ""
# Begin Group "General (WJS)"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\Tests\WrappedJS\General\XPCIDispatchTestWrappedJS.js
# End Source File
# End Group
# Begin Source File
SOURCE=..\Tests\WrappedJS\shell.js
# End Source File
# End Group
# End Group
# End Target
# End Project

View File

@@ -1,29 +0,0 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "XPCIDispatchTest"=.\XPCIDispatchTest.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -1,454 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the IDispatch implementation for XPConnect
*
* The Initial Developer of the Original Code is
* David Bradley.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// XPCIDispatchTest.idl : IDL source for XPCIDispatchTest.dll
//
// This file will be processed by the MIDL tool to
// produce the type library (XPCIDispatchTest.tlb) and marshalling code.
import "oaidl.idl";
import "ocidl.idl";
import "objsafe.idl";
[
uuid(83A51226-F49D-488A-8F78-75BB2F927F4C),
version(1.0),
helpstring("XPCIDispatchTest 1.0 Type Library")
]
library IDispatchTestLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
object,
uuid(0de5dbae-1d78-45cb-91a2-24516fef2837),
dual,
helpstring("nsIXPCDispSimple interface"),
pointer_default(unique)
]
interface nsIXPCDispSimple : IDispatch
{
[id(1), helpstring("Simple method returning the name of the class")]
HRESULT ClassName([out]BSTR * name);
[propget, id(2), helpstring("Simple number property")]
HRESULT Number([out, retval]long * result);
[propput, id(2), helpstring("Simple number property")]
HRESULT Number([in]long result);
}
[
uuid(9F39237C-D179-4260-8EF3-4B6D4D7D5570),
helpstring("nsXPCDispSimple Class")
]
coclass nsXPCDispSimple
{
[default] interface nsIXPCDispSimple;
};
[
object,
uuid(47bf6c99-a30c-4105-8af6-de76dcfdd6dd),
dual,
helpstring("nsIXPCDispTestMethods interface"),
pointer_default(unique)
]
interface nsIXPCDispTestMethods : IDispatch
{
/* Return values test */
[id(1), helpstring("method with no parameters")]
HRESULT NoParameters();
[id(2), helpstring("method that returns a string")]
HRESULT ReturnBSTR([out, retval]BSTR * result);
[id(3), helpstring("method that returns a 32 bit signed integer")]
HRESULT ReturnI4([out, retval]int * result);
[id(4), helpstring("method that returns an 8 bit unsigned integer")]
HRESULT ReturnUI1([out, retval]unsigned char * result);
[id(5), helpstring("method that returns a 16 bit signed integer")]
HRESULT ReturnI2([out, retval]short * result);
[id(6), helpstring("method that returns a 32 bit floating point number")]
HRESULT ReturnR4([out, retval]float * result);
[id(7), helpstring("method that returns a 64 bit floating point number")]
HRESULT ReturnR8([out, retval]double * result);
[id(8), helpstring("method that returns a boolean")]
HRESULT ReturnBool([out, retval]VARIANT_BOOL * result);
[id(9), helpstring("method that returns an IDispatch pointer")]
HRESULT ReturnIDispatch([out, retval]IDispatch ** result);
[id(10), helpstring("method that returns an error")]
HRESULT ReturnError([out, retval]SCODE * result);
[id(12), helpstring("method that returns a date")]
HRESULT ReturnDate([out, retval]DATE * result);
[id(13), helpstring("method that returns an IUnknown")]
HRESULT ReturnIUnknown([out, retval]IUnknown ** result);
[id(14), helpstring("method that returns a signed 8 bit integer")]
HRESULT ReturnI1([out, retval]char * result);
[id(15), helpstring("method that returns an unsigned 16 bit integer")]
HRESULT ReturnUI2([out, retval]unsigned short * result);
[id(16), helpstring("method that returns an unsigned 32 bit integer")]
HRESULT ReturnUI4([out, retval]unsigned long * result);
[id(17), helpstring("method that returns an integer")]
HRESULT ReturnInt([out, retval]int * result);
[id(18), helpstring("method that returns an unsigned integer")]
HRESULT ReturnUInt([out, retval]unsigned int * result);
/* Single input parameter tests */
[id(19), helpstring("method that takes a string")]
HRESULT TakesBSTR([in]BSTR result);
[id(20), helpstring("method that takes a 32 bit signed integer")]
HRESULT TakesI4([in]int result);
[id(21), helpstring("method that takes an 8 bit unsigned integer")]
HRESULT TakesUI1([in]unsigned char result);
[id(22), helpstring("method that takes a 16 bit signed integer")]
HRESULT TakesI2([in]short result);
[id(23), helpstring("method that takes a 32 bit floating point number")]
HRESULT TakesR4([in]float result);
[id(24), helpstring("method that takes a 64 bit floating point number")]
HRESULT TakesR8([in]double result);
[id(25), helpstring("method that takes a boolean")]
HRESULT TakesBool([in]VARIANT_BOOL result);
[id(26), helpstring("method that takes an IDispatch pointer")]
HRESULT TakesIDispatch([in]IDispatch * result);
[id(27), helpstring("method that takes an error")]
HRESULT TakesError([in]SCODE result);
[id(29), helpstring("method that takes a date")]
HRESULT TakesDate([in]DATE result);
[id(30), helpstring("method that takes an IUnknown")]
HRESULT TakesIUnknown([in]IUnknown * result);
[id(31), helpstring("method that takes a signed 8 bit integer")]
HRESULT TakesI1([in]char result);
[id(32), helpstring("method that takes an unsigned 16 bit integer")]
HRESULT TakesUI2([in]unsigned short result);
[id(33), helpstring("method that takes an unsigned 32 bit integer")]
HRESULT TakesUI4([in]unsigned long result);
[id(34), helpstring("method that takes an integer")]
HRESULT TakesInt([in]int result);
[id(35), helpstring("method that takes an unsigned integer")]
HRESULT TakesUInt([in]unsigned int result);
/* output parameter tests */
[id(36), helpstring("method that outputs a string")]
HRESULT OutputsBSTR([out]BSTR * result);
[id(37), helpstring("method that outputs a 32 bit signed integer")]
HRESULT OutputsI4([out]long * result);
[id(38), helpstring("method that outputs an 8 bit unsigned integer")]
HRESULT OutputsUI1([out]unsigned char * result);
[id(39), helpstring("method that outputs a 16 bit signed integer")]
HRESULT OutputsI2([out]short * result);
[id(40), helpstring("method that outputs a 32 bit floating point number")]
HRESULT OutputsR4([out]float * result);
[id(41), helpstring("method that outputs a 64 bit floating point number")]
HRESULT OutputsR8([out]double * result);
[id(42), helpstring("method that outputs a boolean")]
HRESULT OutputsBool([out]VARIANT_BOOL * result);
[id(43), helpstring("method that outputs an IDispatch pointer")]
HRESULT OutputsIDispatch([out]IDispatch ** result);
[id(44), helpstring("method that outputs an error")]
HRESULT OutputsError([out]SCODE * result);
[id(46), helpstring("method that outputs a date")]
HRESULT OutputsDate([out]DATE * result);
[id(47), helpstring("method that outputs an IUnknown")]
HRESULT OutputsIUnknown([out]IUnknown ** result);
[id(48), helpstring("method that outputs a signed 8 bit integer")]
HRESULT OutputsI1([out]char * result);
[id(49), helpstring("method that outputs an unsigned 16 bit integer")]
HRESULT OutputsUI2([out]unsigned short * result);
[id(50), helpstring("method that outputs an unsigned 32 bit integer")]
HRESULT OutputsUI4([out]unsigned long * result);
/* in/outparameter tests */
[id(53), helpstring("method that in/outs a string")]
HRESULT InOutsBSTR([in, out]BSTR * result);
[id(54), helpstring("method that in/outs a 32 bit signed integer")]
HRESULT InOutsI4([in, out]long * result);
[id(55), helpstring("method that in/outs an 8 bit unsigned integer")]
HRESULT InOutsUI1([in, out]unsigned char * result);
[id(56), helpstring("method that in/outs a 16 bit signed integer")]
HRESULT InOutsI2([in, out]short * result);
[id(57), helpstring("method that in/outs a 32 bit floating point number")]
HRESULT InOutsR4([in, out]float * result);
[id(58), helpstring("method that in/outs a 64 bit floating point number")]
HRESULT InOutsR8([in, out]double * result);
[id(59), helpstring("method that in/outs a boolean")]
HRESULT InOutsBool([in, out]VARIANT_BOOL * result);
[id(60), helpstring("method that in/outs an IDispatch pointer")]
HRESULT InOutsIDispatch([in, out]IDispatch ** result);
[id(61), helpstring("method that in/outs an error")]
HRESULT InOutsError([in, out]SCODE * result);
[id(63), helpstring("method that in/outs a date")]
HRESULT InOutsDate([in, out]DATE * result);
[id(64), helpstring("method that in/outs an IUnknown")]
HRESULT InOutsIUnknown([in, out]IUnknown ** result);
[id(65), helpstring("method that in/outs a signed 8 bit integer")]
HRESULT InOutsI1([in, out]char * result);
[id(66), helpstring("method that in/outs an unsigned 16 bit integer")]
HRESULT InOutsUI2([in, out]unsigned short * result);
[id(67), helpstring("method that in/outs an unsigned 32 bit integer")]
HRESULT InOutsUI4([in, out]unsigned long * result);
/* input and return tests*/
[id(70), helpstring("method that takes an long and returns it")]
HRESULT OneParameterWithReturn([in]long input, [out,retval]long* result);
[id(71), helpstring("method that takes a string and returns it")]
HRESULT StringInputAndReturn([in]BSTR str, [out, retval]BSTR* result);
[id(72), helpstring("method that takes an IDispatch and returns it")]
HRESULT IDispatchInputAndReturn([in]IDispatch* input, [out,retval]IDispatch** result);
/* Multiple parameters */
[id(73), helpstring("method that takes two parameters")]
HRESULT TwoParameters([in]long one, [in]long two);
[id(74), helpstring("method that takes 12 input parameters")]
HRESULT TwelveInParameters([in]long one, [in]long two, [in]long three,
[in]long four, [in]long five, [in]long six,
[in]long seven, [in]long eight,
[in]long nine, [in]long ten,
[in]long eleven, [in]long twelve);
[id(75), helpstring("method that takes 12 out parameters")]
HRESULT TwelveOutParameters([out]long *one, [out]long *two,
[out]long *three, [out]long *four,
[out]long *five, [out]long *six,
[out]long *seven, [out]long *eight,
[out]long *nine, [out]long *ten,
[out]long *eleven, [out]long *twelve);
[id(76), helpstring("method that takes 12 input string parameters")]
HRESULT TwelveStrings([in]BSTR one, [in]BSTR two, [in]BSTR three,
[in]BSTR four, [in]BSTR five, [in]BSTR six,
[in]BSTR seven, [in]BSTR eight, [in]BSTR nine,
[in]BSTR ten, [in]BSTR eleven, [in]BSTR twelve);
[id(77), helpstring("method that takes 12 input string parameters")]
HRESULT TwelveOutStrings([out]BSTR* one, [out]BSTR* two,
[out]BSTR* three, [out]BSTR* four,
[out]BSTR* five, [out]BSTR* six,
[out]BSTR* seven, [out]BSTR* eight,
[out]BSTR* nine, [out]BSTR* ten,
[out]BSTR* eleven, [out]BSTR* twelve);
[id(78), helpstring("method that takes 12 input string parameters")]
HRESULT TwelveIDispatch([in]IDispatch* one, [in]IDispatch* two,
[in]IDispatch* three, [in]IDispatch* four,
[in]IDispatch* five, [in]IDispatch* six,
[in]IDispatch* seven, [in]IDispatch* eight,
[in]IDispatch* nine, [in]IDispatch* ten,
[in]IDispatch* eleven,
[in]IDispatch* twelve);
[id(79), helpstring("method that takes 12 input string parameters")]
HRESULT TwelveOutIDispatch([out]IDispatch** one,
[out]IDispatch** two,
[out]IDispatch** three,
[out]IDispatch** four,
[out]IDispatch** five,
[out]IDispatch** six,
[out]IDispatch** seven,
[out]IDispatch** eight,
[out]IDispatch** nine,
[out]IDispatch** ten,
[out]IDispatch** eleven,
[out]IDispatch** twelve);
[id(80), helpstring("method that generates an error")]
HRESULT CreateError();
}
[
uuid(745D1149-9F46-418C-B176-71EAA98974BA),
helpstring("nsXPCDispTestMethods Class")
]
coclass nsXPCDispTestMethods
{
[default] interface nsIXPCDispTestMethods;
};
[
object,
uuid(f876c083-ae00-4b78-93b8-8305980f0864),
dual,
helpstring("nsIXPCDispTestArrays interface"),
pointer_default(unique)
]
interface nsIXPCDispTestArrays : IDispatch
{
[id(1), helpstring("returns a SAFEARRAY")]
HRESULT ReturnSafeArray([out, retval]SAFEARRAY(VARIANT)* result);
[id(2), helpstring("returns a SAFEARRAY")]
HRESULT ReturnSafeArrayBSTR([out, retval]SAFEARRAY(VARIANT)* result);
[id(3), helpstring("returns a SAFEARRAY")]
HRESULT ReturnSafeArrayIDispatch([out, retval]SAFEARRAY(VARIANT)* result);
[id(4), helpstring("method that takes a SAFEARRAY")]
HRESULT TakesSafeArray([in]SAFEARRAY(VARIANT) array);
[id(5), helpstring("method that takes a SAFEARRAY")]
HRESULT TakesSafeArrayBSTR([in]SAFEARRAY(VARIANT) array);
[id(6), helpstring("method that takes a SAFEARRAY")]
HRESULT TakesSafeArrayIDispatch([in]SAFEARRAY(VARIANT) array);
[id(7), helpstring("method that takes a SAFEARRAY")]
HRESULT InOutSafeArray([in, out]SAFEARRAY(VARIANT) * array);
[id(8), helpstring("method that takes a SAFEARRAY")]
HRESULT InOutSafeArrayBSTR([in, out]SAFEARRAY(VARIANT) * array);
[id(9), helpstring("method that takes a SAFEARRAY")]
HRESULT InOutSafeArrayIDispatch([in, out]SAFEARRAY(VARIANT) * array);
}
[
uuid(AB085C43-C619-48C8-B68C-C495BDE12DFB),
helpstring("nsXPCDispTestArrays Class")
]
coclass nsXPCDispTestArrays
{
[default] interface nsIXPCDispTestArrays;
};
[
object,
uuid(9782107f-14cc-40b2-b0cd-988d81a46e9e),
dual,
helpstring("nsIXPCDispTestNoIDispatch interface"),
pointer_default(unique)
]
interface nsIXPCDispTestNoIDispatch : IUnknown
{
}
[
uuid(7414404F-A4CC-4E3C-9B32-BB20CB22F541),
helpstring("nsXPCDispTestNoIDispatch Class")
]
coclass nsXPCDispTestNoIDispatch
{
[default] interface nsIXPCDispTestNoIDispatch;
};
[
object,
uuid(7830CACE-5019-489D-8B69-029E70CF39B7),
dual,
helpstring("nsIXPCDispTestProperties Interface"),
pointer_default(unique)
]
interface nsIXPCDispTestProperties : IDispatch
{
[propget, id(1), helpstring("property Short")] HRESULT Short([out, retval] short *pVal);
[propput, id(1), helpstring("property Short")] HRESULT Short([in] short newVal);
[propget, id(2), helpstring("property Long")] HRESULT Long([out, retval] long *pVal);
[propput, id(2), helpstring("property Long")] HRESULT Long([in] long newVal);
[propget, id(3), helpstring("property Float")] HRESULT Float([out, retval] float *pVal);
[propput, id(3), helpstring("property Float")] HRESULT Float([in] float newVal);
[propget, id(4), helpstring("property Double")] HRESULT Double([out, retval] double *pVal);
[propput, id(4), helpstring("property Double")] HRESULT Double([in] double newVal);
[propget, id(5), helpstring("property Currency")] HRESULT Currency([out, retval] CURRENCY *pVal);
[propput, id(5), helpstring("property Currency")] HRESULT Currency([in] CURRENCY newVal);
[propget, id(6), helpstring("property Date")] HRESULT Date([out, retval] DATE *pVal);
[propput, id(6), helpstring("property Date")] HRESULT Date([in] DATE newVal);
[propget, id(7), helpstring("property String")] HRESULT String([out, retval] BSTR *pVal);
[propput, id(7), helpstring("property String")] HRESULT String([in] BSTR newVal);
[propget, id(8), helpstring("property DispatchPtr")] HRESULT DispatchPtr([out, retval] IDispatch* *pVal);
[propput, id(8), helpstring("property DispatchPtr")] HRESULT DispatchPtr([in] IDispatch* newVal);
[propget, id(9), helpstring("property SCode")] HRESULT SCode([out, retval] SCODE *pVal);
[propput, id(9), helpstring("property SCode")] HRESULT SCode([in] SCODE newVal);
[propget, id(10), helpstring("property Boolean")] HRESULT Boolean([out, retval] BOOL *pVal);
[propput, id(10), helpstring("property Boolean")] HRESULT Boolean([in] BOOL newVal);
[propget, id(11), helpstring("property Variant")] HRESULT Variant([out, retval] VARIANT *pVal);
[propput, id(11), helpstring("property Variant")] HRESULT Variant([in] VARIANT newVal);
[propget, id(12), helpstring("property COMPtr")] HRESULT COMPtr([out, retval] IUnknown* *pVal);
[propput, id(12), helpstring("property COMPtr")] HRESULT COMPtr([in] IUnknown* newVal);
[propget, id(13), helpstring("property Char")] HRESULT Char([out, retval] unsigned char *pVal);
[propput, id(13), helpstring("property Char")] HRESULT Char([in] unsigned char newVal);
[propget, id(14), helpstring("property ParameterizedProperty")] HRESULT ParameterizedProperty([in]long aIndex, [out, retval] long *pVal);
[propput, id(14), helpstring("property ParameterizedProperty")] HRESULT ParameterizedProperty([in]long aIndex, [in] long newVal);
[propget, id(15), helpstring("property ParameterizedPropertyCount")] HRESULT ParameterizedPropertyCount([out, retval] long *pVal);
};
[
object,
uuid(0797788A-CB08-4995-BD45-7BF8C468DE21),
dual,
helpstring("nsIXPCDispTestScriptOn Interface"),
pointer_default(unique)
]
interface nsIXPCDispTestScriptOn : IDispatch
{
};
[
uuid(2A06373F-3E61-4882-A3D7-A104F70B09ED),
helpstring("nsXPCDispTestScriptOn Class")
]
coclass nsXPCDispTestScriptOn
{
[default] interface nsIXPCDispTestScriptOn;
};
[
object,
uuid(EE6F9DB5-890F-422D-B9DC-9C5AB5A1D654),
dual,
helpstring("nsIXPCDispTestScriptOff Interface"),
pointer_default(unique)
]
interface nsIXPCDispTestScriptOff : IDispatch
{
};
[
object,
uuid(D84352CA-1A01-4E72-9072-77AFA669B3AD),
dual,
helpstring("nsIXPCDispTestWrappedJS Interface"),
pointer_default(unique)
]
interface nsIXPCDispTestWrappedJS : IDispatch
{
[id(1), helpstring("method TestParamTypes")] HRESULT TestParamTypes([in] IDispatch * obj, [out, retval]BSTR * errMsg);
};
[
uuid(EAEE6BB2-C005-4B91-BCA7-6613236F6F69),
helpstring("nsXPCDispTestWrappedJS Class")
]
coclass nsXPCDispTestWrappedJS
{
[default] interface nsIXPCDispTestWrappedJS;
};
[
uuid(959CD122-9826-4757-BA09-DE327D55F9E7),
helpstring("nsXPCDispTestScriptOff Class")
]
coclass nsXPCDispTestScriptOff
{
[default] interface nsIXPCDispTestScriptOff;
};
[
uuid(D8B4265B-1768-4CA9-A285-7CCAEEB51C74),
helpstring("nsXPCDispTestProperties Class")
]
coclass nsXPCDispTestProperties
{
[default] interface nsIXPCDispTestProperties;
};
};

View File

@@ -1,145 +0,0 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"1 TYPELIB ""XPCIDispatchTest.tlb""\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "\0"
VALUE "FileDescription", "XPCIDispatchTest Module\0"
VALUE "FileVersion", "1, 0, 0, 1\0"
VALUE "InternalName", "XPCIDispatchTest\0"
VALUE "LegalCopyright", "Copyright 2002\0"
VALUE "OriginalFilename", "XPCIDispatchTest.DLL\0"
VALUE "ProductName", "XPCIDispatchTest Module\0"
VALUE "ProductVersion", "1, 0, 0, 1\0"
VALUE "OLESelfRegister", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
/////////////////////////////////////////////////////////////////////////////
//
// REGISTRY
//
IDR_nsXPCDispTestMethods REGISTRY DISCARDABLE "nsXPCDispTestMethods.rgs"
IDR_nsXPCDispSimple REGISTRY DISCARDABLE "nsXPCDispSimple.rgs"
IDR_nsXPCDispTestNoIDispatch REGISTRY DISCARDABLE "nsXPCDispTestNoIDispatch.rgs"
IDR_nsXPCDispTestProperties REGISTRY DISCARDABLE "nsXPCDispTestProperties.rgs"
IDR_nsXPCDispTestArrays REGISTRY DISCARDABLE "nsXPCDispTestArrays.rgs"
IDR_nsXPCDispTestScriptOn REGISTRY DISCARDABLE "nsXPCDispTestScriptOn.rgs"
IDR_nsXPCDispTestScriptOff REGISTRY DISCARDABLE "nsXPCDispTestScriptOff.rgs"
IDR_nsXPCDispTestWrappedJS REGISTRY DISCARDABLE "nsXPCDispTestWrappedJS.rgs"
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE DISCARDABLE
BEGIN
IDS_PROJNAME "XPCIDispatchTest"
IDS_NSXPCDISPTTESTMETHODS_DESC "nsXPCDisptTestMethods Class"
IDS_NSXPCDISPTESTMETHODS_DESC "nsXPCDispTestMethods Class"
IDS_NSXPCDISPSIMPLE_DESC "nsXPCDispSimple Class"
IDS_NSXPCDISPTESTNOIDISPATCH_DESC "nsXPCDispTestNoIDispatch Class"
IDS_NSXPCDISPTESTNOSCRIPT_DESC "nsXPCDispTestNoScript Class"
IDS_NSXPCDISPTESTPROPERTIES_DESC "nsXPCDispTestProperties Class"
END
STRINGTABLE DISCARDABLE
BEGIN
IDS_NSXPCDISPTESTARRAYS_DESC "nsXPCDispTestArrays Class"
IDS_NSXPCDISPTESTSCRIPTON_DESC "nsXPCDispTestScriptOn Class"
IDS_NSXPCDISPTESTSCRIPTOFF_DESC "nsXPCDispTestScriptOff Class"
IDS_NSXPCDISPTESTWRAPPEDJS_DESC "nsXPCDispTestWrappedJS Class"
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
1 TYPELIB "XPCIDispatchTest.tlb"
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -1,44 +0,0 @@
// nsXPCDispSimple.cpp : Implementation of CXPCIDispatchTestApp and DLL registration.
#include "stdafx.h"
#include "XPCIDispatchTest.h"
#include "nsXPCDispSimple.h"
/////////////////////////////////////////////////////////////////////////////
//
STDMETHODIMP nsXPCDispSimple::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_nsIXPCDispSimple,
};
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP nsXPCDispSimple::ClassName(BSTR * name)
{
if (name == NULL)
return E_POINTER;
CComBSTR x("nsXPCDispSimple");
*name = x.Detach();
return S_OK;
}
STDMETHODIMP nsXPCDispSimple::get_Number(LONG * result)
{
if (result == NULL)
return E_POINTER;
*result = mNumber;
return S_OK;
}
STDMETHODIMP nsXPCDispSimple::put_Number(LONG result)
{
mNumber = result;
return S_OK;
}

View File

@@ -1,56 +0,0 @@
// nsXPCDispSimple.h: Definition of the nsXPCDispSimple class
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_NSXPCDISPSIMPLE_H__5502A675_46D9_4762_A7F9_1A023A052152__INCLUDED_)
#define AFX_NSXPCDISPSIMPLE_H__5502A675_46D9_4762_A7F9_1A023A052152__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// nsXPCDispSimple
class nsXPCDispSimple :
public ISupportErrorInfo,
public CComObjectRoot,
public CComCoClass<nsXPCDispSimple,&CLSID_nsXPCDispSimple>,
public IDispatchImpl<nsIXPCDispSimple, &IID_nsIXPCDispSimple, &LIBID_IDispatchTestLib>
{
public:
nsXPCDispSimple() : mNumber(5) {}
BEGIN_CATEGORY_MAP(nsXPCDispSimple)
IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
END_CATEGORY_MAP()
BEGIN_COM_MAP(nsXPCDispSimple)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY(nsIXPCDispSimple)
END_COM_MAP()
DECLARE_NOT_AGGREGATABLE(nsXPCDispSimple)
DECLARE_REGISTRY_RESOURCEID(IDR_nsXPCDispSimple)
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// nsIXPCDispSimple
public:
// nsIXPCDispSimple
STDMETHOD(ClassName)(BSTR * name);
STDMETHOD(get_Number)(LONG * result);
STDMETHOD(put_Number)(LONG result);
template <class T>
static HRESULT CreateInstance(T ** result)
{
return CoCreateInstance(CLSID_nsXPCDispSimple, 0, CLSCTX_ALL,
__uuidof(T),
reinterpret_cast<void**>(result));
}
private:
long mNumber;
};
#endif // !defined(AFX_NSXPCDISPSIMPLE_H__5502A675_46D9_4762_A7F9_1A023A052152__INCLUDED_)

View File

@@ -1,23 +0,0 @@
HKCR
{
XPCIDispatchTest.nsXPCDispSimple.1 = s 'nsXPCDispSimple Class'
{
CLSID = s '{9F39237C-D179-4260-8EF3-4B6D4D7D5570}'
}
XPCIDispatchTest.nsXPCDispSimple = s 'nsXPCDispSimple Class'
{
CLSID = s '{9F39237C-D179-4260-8EF3-4B6D4D7D5570}'
}
NoRemove CLSID
{
ForceRemove {9F39237C-D179-4260-8EF3-4B6D4D7D5570} = s 'nsXPCDispSimple Class'
{
ProgID = s 'XPCIDispatchTest.nsXPCDispSimple.1'
VersionIndependentProgID = s 'XPCIDispatchTest.nsXPCDispSimple'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'both'
}
}
}
}

View File

@@ -1,221 +0,0 @@
// nsXPCDispTestArrays.cpp : Implementation of CXPCIDispatchTestApp and DLL registration.
#include "stdafx.h"
#include "XPCIDispatchTest.h"
#include "nsXPCDispTestArrays.h"
unsigned int zero = 0;
/////////////////////////////////////////////////////////////////////////////
//
STDMETHODIMP nsXPCDispTestArrays::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_nsIXPCDispTestArrays,
};
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP nsXPCDispTestArrays::ReturnSafeArray(LPSAFEARRAY * result)
{
if (result == NULL)
return E_POINTER;
*result = SafeArrayCreateVector(VT_I4, 0, 3);
for (long index = 0; index < 3; ++index)
{
SafeArrayPutElement(*result, &index, &index);
}
return S_OK;
}
STDMETHODIMP nsXPCDispTestArrays::ReturnSafeArrayBSTR(LPSAFEARRAY * result)
{
if (result == NULL)
return E_POINTER;
*result = SafeArrayCreateVector(VT_BSTR, 0, 3);
for (long index = 0; index < 3; ++index)
{
_variant_t var(index);
HRESULT hr = VariantChangeType(&var, &var, VARIANT_ALPHABOOL, VT_BSTR);
if (FAILED(hr))
return hr;
SafeArrayPutElement(*result, &index, var.bstrVal);
}
return S_OK;
}
STDMETHODIMP nsXPCDispTestArrays::ReturnSafeArrayIDispatch(LPSAFEARRAY * result)
{
if (result == NULL)
return E_POINTER;
*result = SafeArrayCreateVector(VT_DISPATCH, 0, 3);
for (long index = 0; index < 3; ++index)
{
CComPtr<nsIXPCDispSimple> ptr;
ptr.CoCreateInstance(CLSID_nsXPCDispSimple);
SafeArrayPutElement(*result, &index, ptr.p);
}
return S_OK;
}
#define RETURN_IF_FAIL(x) hr = x; if (FAILED(hr)) return hr;
STDMETHODIMP nsXPCDispTestArrays::TakesSafeArray(LPSAFEARRAY array)
{
long lbound;
long ubound;
HRESULT hr;
RETURN_IF_FAIL(SafeArrayGetLBound(array, 1, &lbound));
if (lbound != 0)
return E_FAIL;
RETURN_IF_FAIL(SafeArrayGetUBound(array, 1, &ubound));
if (ubound != 3)
return E_FAIL;
for (long index = lbound; index <= ubound; ++index)
{
_variant_t value;
RETURN_IF_FAIL(SafeArrayGetElement(array, &index, &value));
if (value != _variant_t(index))
return E_FAIL;
}
return S_OK;
}
STDMETHODIMP nsXPCDispTestArrays::TakesSafeArrayBSTR(LPSAFEARRAY array)
{
long lbound;
long ubound;
HRESULT hr;
RETURN_IF_FAIL(SafeArrayGetLBound(array, 1, &lbound));
if (lbound != 0)
return E_FAIL;
RETURN_IF_FAIL(SafeArrayGetUBound(array, 1, &ubound));
if (ubound != 3)
return E_FAIL;
for (long index = lbound; index <= ubound; ++index)
{
_variant_t value;
RETURN_IF_FAIL(SafeArrayGetElement(array, &index, &value));
_variant_t test(index);
if (_bstr_t(value) != _bstr_t(test))
return E_FAIL;
}
return S_OK;
}
STDMETHODIMP nsXPCDispTestArrays::TakesSafeArrayIDispatch(LPSAFEARRAY array)
{
long lbound;
long ubound;
HRESULT hr;
RETURN_IF_FAIL(SafeArrayGetLBound(array, 0, &lbound));
if (lbound != 0)
return E_FAIL;
RETURN_IF_FAIL(SafeArrayGetUBound(array, 0, &ubound));
if (ubound != 3)
return E_FAIL;
for (long index = lbound; index <= ubound; ++index)
{
_variant_t value;
RETURN_IF_FAIL(SafeArrayGetElement(array, &index, &value));
// We need to do more here, but this is good enough for now
if (!value.pdispVal)
return E_FAIL;
}
return S_OK;
}
STDMETHODIMP nsXPCDispTestArrays::InOutSafeArray(LPSAFEARRAY * array)
{
if (array == NULL)
return E_POINTER;
long lbound;
long ubound;
HRESULT hr;
RETURN_IF_FAIL(SafeArrayGetLBound(*array, 0, &lbound));
if (lbound != 0)
return E_FAIL;
RETURN_IF_FAIL(SafeArrayGetUBound(*array, 0, &ubound));
if (ubound != 3)
return E_FAIL;
LPSAFEARRAY newArray = SafeArrayCreateVector(VT_I4, lbound, ubound);
for (long index = lbound; index <= ubound; ++index)
{
long value;
RETURN_IF_FAIL(SafeArrayGetElement(*array, &index, &value));
if (value != index)
return E_FAIL;
value += 42;
RETURN_IF_FAIL(SafeArrayPutElement(newArray, &index, &value));
}
SafeArrayDestroy(*array);
*array = newArray;
return S_OK;
}
STDMETHODIMP nsXPCDispTestArrays::InOutSafeArrayBSTR(LPSAFEARRAY * array)
{
if (array == NULL)
return E_POINTER;
long lbound;
long ubound;
HRESULT hr;
RETURN_IF_FAIL(SafeArrayGetLBound(*array, 0, &lbound));
if (lbound != 0)
return E_FAIL;
RETURN_IF_FAIL(SafeArrayGetUBound(*array, 0, &ubound));
if (ubound != 3)
return E_FAIL;
LPSAFEARRAY newArray = SafeArrayCreateVector(VT_BSTR, lbound, ubound);
for (long index = lbound; index <= ubound; ++index)
{
BSTR value;
RETURN_IF_FAIL(SafeArrayGetElement(*array, &index, &value));
_bstr_t newValue(value, TRUE);
newValue += L"Appended";
RETURN_IF_FAIL(SafeArrayPutElement(newArray, &index, newValue.copy()));
}
SafeArrayDestroy(*array);
*array = newArray;
return S_OK;
}
STDMETHODIMP nsXPCDispTestArrays::InOutSafeArrayIDispatch(LPSAFEARRAY * array)
{
if (array == NULL)
return E_POINTER;
long lbound;
long ubound;
HRESULT hr;
RETURN_IF_FAIL(SafeArrayGetLBound(*array, 0, &lbound));
if (lbound != 0)
return E_FAIL;
RETURN_IF_FAIL(SafeArrayGetUBound(*array, 0, &ubound));
if (ubound != 3)
return E_FAIL;
LPSAFEARRAY newArray = SafeArrayCreateVector(VT_DISPATCH, lbound, ubound);
for (long index = lbound; index <= ubound; ++index)
{
IDispatch* value;
RETURN_IF_FAIL(SafeArrayGetElement(*array, &index, &value));
RETURN_IF_FAIL(SafeArrayPutElement(newArray, &index, &value));
}
SafeArrayDestroy(*array);
*array = newArray;
return S_OK;
}

View File

@@ -1,53 +0,0 @@
// nsXPCDispTestArrays.h: Definition of the nsXPCDispTestArrays class
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_NSXPCDISPTESTARRAYS_H__5F59BD4C_16A4_4BD6_8281_796DE6A2889C__INCLUDED_)
#define AFX_NSXPCDISPTESTARRAYS_H__5F59BD4C_16A4_4BD6_8281_796DE6A2889C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// nsXPCDispTestArrays
class nsXPCDispTestArrays :
public IDispatchImpl<nsIXPCDispTestArrays, &IID_nsIXPCDispTestArrays, &LIBID_IDispatchTestLib>,
public ISupportErrorInfo,
public CComObjectRoot,
public CComCoClass<nsXPCDispTestArrays,&CLSID_nsXPCDispTestArrays>
{
public:
nsXPCDispTestArrays() {}
BEGIN_CATEGORY_MAP(nsXPCDispTestArrays)
IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
END_CATEGORY_MAP()
BEGIN_COM_MAP(nsXPCDispTestArrays)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY(nsIXPCDispTestArrays)
END_COM_MAP()
DECLARE_NOT_AGGREGATABLE(nsXPCDispTestArrays)
DECLARE_REGISTRY_RESOURCEID(IDR_nsXPCDispTestArrays)
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// nsIXPCDispTestArrays
public:
// nsIXPCDispTestArrays
STDMETHOD(ReturnSafeArray)(LPSAFEARRAY * result);
STDMETHOD(ReturnSafeArrayBSTR)(LPSAFEARRAY * result);
STDMETHOD(ReturnSafeArrayIDispatch)(LPSAFEARRAY * result);
STDMETHOD(TakesSafeArray)(LPSAFEARRAY array);
STDMETHOD(TakesSafeArrayBSTR)(LPSAFEARRAY array);
STDMETHOD(TakesSafeArrayIDispatch)(LPSAFEARRAY array);
STDMETHOD(InOutSafeArray)(LPSAFEARRAY * array);
STDMETHOD(InOutSafeArrayBSTR)(LPSAFEARRAY * array);
STDMETHOD(InOutSafeArrayIDispatch)(LPSAFEARRAY * array);
};
#endif // !defined(AFX_NSXPCDISPTESTARRAYS_H__5F59BD4C_16A4_4BD6_8281_796DE6A2889C__INCLUDED_)

View File

@@ -1,23 +0,0 @@
HKCR
{
XPCIDispatchTest.nsXPCDispTestArrays.1 = s 'nsXPCDispTestArrays Class'
{
CLSID = s '{AB085C43-C619-48C8-B68C-C495BDE12DFB}'
}
XPCIDispatchTest.nsXPCDispTestArrays = s 'nsXPCDispTestArrays Class'
{
CLSID = s '{AB085C43-C619-48C8-B68C-C495BDE12DFB}'
}
NoRemove CLSID
{
ForceRemove {AB085C43-C619-48C8-B68C-C495BDE12DFB} = s 'nsXPCDispTestArrays Class'
{
ProgID = s 'XPCIDispatchTest.nsXPCDispTestArrays.1'
VersionIndependentProgID = s 'XPCIDispatchTest.nsXPCDispTestArrays'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'both'
}
}
}
}

View File

@@ -1,699 +0,0 @@
// nsXPCDispTestMethods.cpp : Implementation of CIDispatchTestApp and DLL registration.
#include "stdafx.h"
#include "XPCIDispatchTest.h"
#include "nsXPCDispTestMethods.h"
#include "XPCDispUtilities.h"
#include "nsXPCDispSimple.h"
/////////////////////////////////////////////////////////////////////////////
//
STDMETHODIMP nsXPCDispTestMethods::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_nsIXPCDispTestMethods,
};
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP nsXPCDispTestMethods::NoParameters()
{
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnBSTR(BSTR * result)
{
if (result == NULL)
return E_POINTER;
CComBSTR x("Boo");
*result = x.Detach();
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnI4(INT * result)
{
if (result == NULL)
return E_POINTER;
*result = 99999;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnUI1(BYTE * result)
{
if (result == NULL)
return E_POINTER;
*result = 99;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnI2(SHORT * result)
{
if (result == NULL)
return E_POINTER;
*result = 9999;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnR4(FLOAT * result)
{
if (result == NULL)
return E_POINTER;
*result = 99999.1f;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnR8(DOUBLE * result)
{
if (result == NULL)
return E_POINTER;
*result = 99999999999.99;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnBool(VARIANT_BOOL * result)
{
if (result == NULL)
return E_POINTER;
*result = VARIANT_TRUE;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnIDispatch(IDispatch * * result)
{
if (result == NULL)
return E_POINTER;
return nsXPCDispSimple::CreateInstance(result);
}
STDMETHODIMP nsXPCDispTestMethods::ReturnError(SCODE * result)
{
if (result == NULL)
return E_POINTER;
*result = E_FAIL;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnDate(DATE * result)
{
if (result == NULL)
return E_POINTER;
CComBSTR dateStr(L"5/2/02");
return VarDateFromStr(dateStr, LOCALE_SYSTEM_DEFAULT,
LOCALE_NOUSEROVERRIDE, result);
}
STDMETHODIMP nsXPCDispTestMethods::ReturnIUnknown(IUnknown * * result)
{
if (result == NULL)
return E_POINTER;
return XPCCreateInstance<IUnknown>(CLSID_nsXPCDispTestNoIDispatch, IID_IUnknown, result);
}
STDMETHODIMP nsXPCDispTestMethods::ReturnI1(unsigned char * result)
{
if (result == NULL)
return E_POINTER;
*result = 120;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnUI2(USHORT * result)
{
if (result == NULL)
return E_POINTER;
*result = 9999;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnUI4(ULONG * result)
{
if (result == NULL)
return E_POINTER;
*result = 3000000000;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnInt(INT * result)
{
if (result == NULL)
return E_POINTER;
*result = -999999;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::ReturnUInt(UINT * result)
{
if (result == NULL)
return E_POINTER;
*result = 3000000000;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::TakesBSTR(BSTR result)
{
CComBSTR str(result);
static CComBSTR test(L"TakesBSTR");
return str == test ? S_OK: E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TakesI4(INT result)
{
return result == 999999 ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TakesUI1(BYTE result)
{
return result == 42 ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TakesI2(SHORT result)
{
return result == 32000 ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TakesR4(FLOAT result)
{
// Hopefully we won't run into any precision/rounding issues
return result == 99999.99f ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TakesR8(DOUBLE result)
{
// Hopefully we won't run into any precision/rounding issues
return result == 999999999.99 ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TakesBool(VARIANT_BOOL result)
{
return result ? S_OK : E_FAIL;
}
inline
HRESULT GetProperty(IDispatch *pDisp, const CComBSTR & name, CComVariant& output)
{
DISPID dispid = GetIDsOfNames(pDisp, name);
DISPPARAMS dispParams;
dispParams.cArgs = 0;
dispParams.cNamedArgs = 0;
dispParams.rgdispidNamedArgs = 0;
dispParams.rgvarg = 0;
return pDisp->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,DISPATCH_PROPERTYGET, &dispParams, &output, 0, 0);
}
inline
HRESULT PutProperty(IDispatch *pDisp, const CComBSTR & name, const CComVariant& input)
{
DISPPARAMS dispParams;
DISPID did = DISPID_PROPERTYPUT;
dispParams.cArgs = 1;
CComVariant var(input);
dispParams.rgvarg = &var;
dispParams.cNamedArgs = 1;
dispParams.rgdispidNamedArgs = &did;
CComVariant result;
DISPID dispID = GetIDsOfNames(pDisp, name);
return pDisp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYPUT, &dispParams, &result,
0, 0);
}
HRESULT VerifynsXPCDispSimple(IDispatch * result)
{
CComVariant property;
HRESULT hResult = GetProperty(result, L"Number", property);
CComVariant test((long)5);
if (FAILED(hResult))
return hResult;
if (property != test)
return E_FAIL;
return PutProperty(result, L"Number", 76);
}
STDMETHODIMP nsXPCDispTestMethods::TakesIDispatch(IDispatch * result)
{
return VerifynsXPCDispSimple(result);
}
STDMETHODIMP nsXPCDispTestMethods::TakesError(SCODE result)
{
return result == E_FAIL ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TakesDate(DATE result)
{
CComBSTR dateStr(L"5/2/02");
DATE myDate;
HRESULT hResult = VarDateFromStr(dateStr, LOCALE_SYSTEM_DEFAULT,
LOCALE_NOUSEROVERRIDE, &myDate);
if (SUCCEEDED(hResult))
return myDate == result ? S_OK : E_FAIL;
else
return hResult;
}
STDMETHODIMP nsXPCDispTestMethods::TakesIUnknown(IUnknown * result)
{
CComPtr<IUnknown> ptr(result);
ULONG before = result->AddRef();
ULONG after = result->Release();
CComQIPtr<nsIXPCDispTestNoIDispatch> noIDispatch(ptr);
return before - 1 == after ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TakesI1(unsigned char result)
{
return result == 42 ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TakesUI2(USHORT result)
{
return result == 50000 ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TakesUI4(ULONG result)
{
return result == 0xF0000000 ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TakesInt(INT result)
{
return result == -10000000 ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TakesUInt(UINT result)
{
return result == 0xE0000000 ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::OutputsBSTR(BSTR * result)
{
if (result == NULL)
return E_POINTER;
CComBSTR x("Boo");
*result = x.Detach();
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::OutputsI4(LONG * result)
{
if (result == NULL)
return E_POINTER;
*result = 99999;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::OutputsUI1(BYTE * result)
{
if (result == NULL)
return E_POINTER;
*result = 99;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::OutputsI2(SHORT * result)
{
if (result == NULL)
return E_POINTER;
*result = 9999;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::OutputsR4(FLOAT * result)
{
if (result == NULL)
return E_POINTER;
*result = 999999.1f;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::OutputsR8(DOUBLE * result)
{
if (result == NULL)
return E_POINTER;
*result = 99999999999.99;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::OutputsBool(VARIANT_BOOL * result)
{
if (result == NULL)
return E_POINTER;
*result = VARIANT_TRUE;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::OutputsIDispatch(IDispatch * * result)
{
if (result == NULL)
return E_POINTER;
return nsXPCDispSimple::CreateInstance(result);
}
STDMETHODIMP nsXPCDispTestMethods::OutputsError(SCODE * result)
{
if (result == NULL)
return E_POINTER;
*result = E_FAIL;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::OutputsDate(DATE * result)
{
if (result == NULL)
return E_POINTER;
CComBSTR dateStr(L"5/2/02");
return VarDateFromStr(dateStr, LOCALE_SYSTEM_DEFAULT,
LOCALE_NOUSEROVERRIDE, result);
}
STDMETHODIMP nsXPCDispTestMethods::OutputsIUnknown(IUnknown * * result)
{
if (result == NULL)
return E_POINTER;
return XPCCreateInstance<IUnknown>(CLSID_nsXPCDispTestNoIDispatch, IID_IUnknown, result);
}
STDMETHODIMP nsXPCDispTestMethods::OutputsI1(unsigned char * result)
{
if (result == NULL)
return E_POINTER;
*result = L'x';
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::OutputsUI2(USHORT * result)
{
if (result == NULL)
return E_POINTER;
*result = 9999;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::OutputsUI4(ULONG * result)
{
if (result == NULL)
return E_POINTER;
*result = 3000000000;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::InOutsBSTR(BSTR * result)
{
if (result == NULL)
return E_POINTER;
CComBSTR str(*result);
str += L"Appended";
SysFreeString(*result);
*result = str.Detach();
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::InOutsI4(LONG * result)
{
if (result == NULL)
return E_POINTER;
*result -= 4000000;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::InOutsUI1(BYTE * result)
{
if (result == NULL)
return E_POINTER;
*result -= 42;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::InOutsI2(SHORT * result)
{
if (result == NULL)
return E_POINTER;
*result += 10000;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::InOutsR4(FLOAT * result)
{
if (result == NULL)
return E_POINTER;
*result += 5.05f;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::InOutsR8(DOUBLE * result)
{
if (result == NULL)
return E_POINTER;
*result += 50000000.00000005;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::InOutsBool(VARIANT_BOOL * result)
{
if (result == NULL)
return E_POINTER;
*result = !*result;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::InOutsIDispatch(IDispatch * * result)
{
if (result == NULL)
return E_POINTER;
CComPtr<nsIXPCDispSimple> ptr;
ptr.CoCreateInstance(CLSID_nsXPCDispSimple);
CComPtr<IDispatch> incoming(*result);
CComVariant value;
HRESULT hResult = GetProperty(incoming, L"Number", value);
if (FAILED(hResult))
return hResult;
if (value.lVal != 10)
return E_FAIL;
hResult = ptr->put_Number(value.lVal + 5);
if (FAILED(hResult))
return hResult;
*result = ptr.Detach();
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::InOutsError(SCODE * result)
{
if (result == NULL)
return E_POINTER;
*result += 1;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::InOutsDate(DATE * result)
{
if (result == NULL)
return E_POINTER;
ULONG days;
HRESULT hResult = VarUI4FromDate(*result, &days);
if (FAILED(hResult))
return hResult;
return VarDateFromUI4(days + 1, result);
}
STDMETHODIMP nsXPCDispTestMethods::InOutsIUnknown(IUnknown * * result)
{
if (result == NULL)
return E_POINTER;
CComPtr<IUnknown> ptr(*result);
ULONG before = (*result)->AddRef();
ULONG after = (*result)->Release();
if (before - 1 != after)
return E_FAIL;
return nsXPCDispSimple::CreateInstance(result);
}
STDMETHODIMP nsXPCDispTestMethods::InOutsI1(unsigned char * result)
{
if (result == NULL)
return E_POINTER;
++*result;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::InOutsUI2(USHORT * result)
{
if (result == NULL)
return E_POINTER;
*result += 42;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::InOutsUI4(ULONG * result)
{
if (result == NULL)
return E_POINTER;
*result -= 42;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::OneParameterWithReturn(LONG input,
LONG * result)
{
if (result == NULL)
return E_POINTER;
*result = input + 42;
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::StringInputAndReturn(BSTR str,
BSTR * result)
{
if (result == NULL)
return E_POINTER;
CComBSTR input(str);
input += L"Appended";
*result = input.Detach();
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::IDispatchInputAndReturn(IDispatch * input, IDispatch * * result)
{
if (result == NULL)
return E_POINTER;
HRESULT hResult = VerifynsXPCDispSimple(input);
hResult = XPCCreateInstance<IDispatch>(CLSID_nsXPCDispSimple, IID_IDispatch, result);
if (FAILED(hResult))
return hResult;
CComVariant variant;
hResult = GetProperty(input, L"Number", variant);
if (FAILED(hResult))
return hResult;
return PutProperty(*result, L"Number", variant.lVal + 5);
}
STDMETHODIMP nsXPCDispTestMethods::TwoParameters(LONG one, LONG two)
{
return one + 1 == two ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TwelveInParameters(LONG one, LONG two,
LONG three, LONG four,
LONG five, LONG six,
LONG seven, LONG eight,
LONG nine, LONG ten,
LONG eleven, LONG twelve)
{
return one + two + three + four + five + six + seven + eight + nine +
ten + eleven + twelve == 78 ? S_OK : E_FAIL;
}
STDMETHODIMP nsXPCDispTestMethods::TwelveOutParameters(LONG * one, LONG * two,
LONG * three,
LONG * four,
LONG * five, LONG * six,
LONG * seven,
LONG * eight,
LONG * nine, LONG * ten,
LONG * eleven,
LONG * twelve)
{
if (one == 0 || two == 0 || three == 0 || four == 0 ||
five == 0 || six == 0 || seven == 0 || eight == 0 ||
nine == 0 || ten == 0 || eleven == 0 || twelve == 0)
return E_POINTER;
*one = 1;
*two = 2;
*three = 3;
*four = 4;
*five = 5;
*six = 6;
*seven = 7;
*eight = 8;
*nine = 9;
*ten = 10;
*eleven = 11;
*twelve = 12;
return S_OK;
}
inline
boolean Equals(BSTR left, const char * str)
{
return CComBSTR(left) == str;
}
#define TESTPARAM(val) Equals(val, #val)
STDMETHODIMP nsXPCDispTestMethods::TwelveStrings(BSTR one, BSTR two, BSTR three, BSTR four, BSTR five, BSTR six, BSTR seven, BSTR eight, BSTR nine, BSTR ten, BSTR eleven, BSTR twelve)
{
return TESTPARAM(one) && TESTPARAM(two) && TESTPARAM(three) &&
TESTPARAM(four) && TESTPARAM(five) && TESTPARAM(six) &&
TESTPARAM(seven) && TESTPARAM(eight) && TESTPARAM(nine) &&
TESTPARAM(ten) && TESTPARAM(eleven) && TESTPARAM(twelve) ?
S_OK : E_FAIL;
}
#define ASSIGNPARAM(val) \
if (val == 0) \
return E_POINTER; \
*val = CComBSTR(#val).Detach()
STDMETHODIMP nsXPCDispTestMethods::TwelveOutStrings(BSTR * one, BSTR * two, BSTR * three, BSTR * four, BSTR * five, BSTR * six, BSTR * seven, BSTR * eight, BSTR * nine, BSTR * ten, BSTR * eleven, BSTR * twelve)
{
ASSIGNPARAM(one);
ASSIGNPARAM(two);
ASSIGNPARAM(three);
ASSIGNPARAM(four);
ASSIGNPARAM(five);
ASSIGNPARAM(six);
ASSIGNPARAM(seven);
ASSIGNPARAM(eight);
ASSIGNPARAM(nine);
ASSIGNPARAM(ten);
ASSIGNPARAM(eleven);
ASSIGNPARAM(twelve);
return S_OK;
}
#define VERIFYSIMPLE(param) \
hResult = VerifynsXPCDispSimple(param); \
if (FAILED(hResult)) \
return hResult
STDMETHODIMP nsXPCDispTestMethods::TwelveIDispatch(IDispatch * one,
IDispatch * two,
IDispatch * three,
IDispatch * four,
IDispatch * five,
IDispatch * six,
IDispatch * seven,
IDispatch * eight,
IDispatch * nine,
IDispatch * ten,
IDispatch * eleven,
IDispatch * twelve)
{
HRESULT hResult;
VERIFYSIMPLE(one);
VERIFYSIMPLE(two);
VERIFYSIMPLE(three);
VERIFYSIMPLE(four);
VERIFYSIMPLE(five);
VERIFYSIMPLE(six);
VERIFYSIMPLE(seven);
VERIFYSIMPLE(eight);
VERIFYSIMPLE(nine);
VERIFYSIMPLE(ten);
VERIFYSIMPLE(eleven);
VERIFYSIMPLE(twelve);
return S_OK;
}
#define ASSIGNSIMPLE(param) \
if (param == 0) \
return E_POINTER; \
hResult = nsXPCDispSimple::CreateInstance(param); \
if (FAILED(hResult)) \
return hResult; \
STDMETHODIMP nsXPCDispTestMethods::TwelveOutIDispatch(IDispatch * * one,
IDispatch * * two,
IDispatch * * three,
IDispatch * * four,
IDispatch * * five,
IDispatch * * six,
IDispatch * * seven,
IDispatch * * eight,
IDispatch * * nine,
IDispatch * * ten,
IDispatch * * eleven,
IDispatch * * twelve){
HRESULT hResult;
ASSIGNSIMPLE(one);
ASSIGNSIMPLE(two);
ASSIGNSIMPLE(three);
ASSIGNSIMPLE(four);
ASSIGNSIMPLE(five);
ASSIGNSIMPLE(six);
ASSIGNSIMPLE(seven);
ASSIGNSIMPLE(eight);
ASSIGNSIMPLE(nine);
ASSIGNSIMPLE(ten);
ASSIGNSIMPLE(eleven);
ASSIGNSIMPLE(twelve);
return S_OK;
}
STDMETHODIMP nsXPCDispTestMethods::CreateError()
{
CComBSTR someText(L"CreateError Test");
ICreateErrorInfo * pCreateError;
IErrorInfo * pError;
HRESULT result = CreateErrorInfo(&pCreateError);
if (FAILED(result))
return E_NOTIMPL;
result = pCreateError->QueryInterface(&pError);
if (FAILED(result))
return E_NOTIMPL;
result = pCreateError->SetDescription(someText);
if (FAILED(result))
return E_NOTIMPL;
result = pCreateError->SetGUID(IID_nsIXPCDispTestMethods);
if (FAILED(result))
return E_NOTIMPL;
CComBSTR source(L"XPCIDispatchTest.nsXPCDispTestMethods.1");
result = pCreateError->SetSource(source);
if (FAILED(result))
return E_NOTIMPL;
result = SetErrorInfo(0, pError);
if (FAILED(result))
return E_NOTIMPL;
pError->Release();
pCreateError->Release();
return E_FAIL;
}

View File

@@ -1,138 +0,0 @@
// nsXPCDispTestMethods.h: Definition of the nsXPCDispTestMethods class
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_NSXPCDISPTESTMETHODS_H__A516B1D7_1971_419C_AE35_EDFAC27D1227__INCLUDED_)
#define AFX_NSXPCDISPTESTMETHODS_H__A516B1D7_1971_419C_AE35_EDFAC27D1227__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "resource.h" // main symbols
#include "XPCIDispatchTest.h"
/////////////////////////////////////////////////////////////////////////////
// nsXPCDispTestMethods
class nsXPCDispTestMethods :
public ISupportErrorInfo,
public CComObjectRoot,
public CComCoClass<nsXPCDispTestMethods,&CLSID_nsXPCDispTestMethods>,
public IDispatchImpl<nsIXPCDispTestMethods, &IID_nsIXPCDispTestMethods, &LIBID_IDispatchTestLib>
{
public:
nsXPCDispTestMethods() {}
BEGIN_CATEGORY_MAP(nsXPCDispTestMethods)
IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
END_CATEGORY_MAP()
BEGIN_COM_MAP(nsXPCDispTestMethods)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY(nsIXPCDispTestMethods)
END_COM_MAP()
DECLARE_NOT_AGGREGATABLE(nsXPCDispTestMethods)
DECLARE_REGISTRY_RESOURCEID(IDR_nsXPCDispTestMethods)
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// nsIXPCDispTestMethods
public:
// nsIXPCDispTestMethod
STDMETHOD(NoParameters)();
STDMETHOD(ReturnBSTR)(BSTR * result);
STDMETHOD(ReturnI4)(INT * result);
STDMETHOD(ReturnUI1)(BYTE * result);
STDMETHOD(ReturnI2)(SHORT * result);
STDMETHOD(ReturnR4)(FLOAT * result);
STDMETHOD(ReturnR8)(DOUBLE * result);
STDMETHOD(ReturnBool)(VARIANT_BOOL * result);
STDMETHOD(ReturnIDispatch)(IDispatch * * result);
STDMETHOD(ReturnError)(SCODE * result);
STDMETHOD(ReturnDate)(DATE * result);
STDMETHOD(ReturnIUnknown)(IUnknown * * result);
STDMETHOD(ReturnI1)(unsigned char * result);
STDMETHOD(ReturnUI2)(USHORT * result);
STDMETHOD(ReturnUI4)(ULONG * result);
STDMETHOD(ReturnInt)(INT * result);
STDMETHOD(ReturnUInt)(UINT * result);
STDMETHOD(TakesBSTR)(BSTR result);
STDMETHOD(TakesI4)(INT result);
STDMETHOD(TakesUI1)(BYTE result);
STDMETHOD(TakesI2)(SHORT result);
STDMETHOD(TakesR4)(FLOAT result);
STDMETHOD(TakesR8)(DOUBLE result);
STDMETHOD(TakesBool)(VARIANT_BOOL result);
STDMETHOD(TakesIDispatch)(IDispatch * result);
STDMETHOD(TakesError)(SCODE result);
STDMETHOD(TakesDate)(DATE result);
STDMETHOD(TakesIUnknown)(IUnknown * result);
STDMETHOD(TakesI1)(unsigned char result);
STDMETHOD(TakesUI2)(USHORT result);
STDMETHOD(TakesUI4)(ULONG result);
STDMETHOD(TakesInt)(INT result);
STDMETHOD(TakesUInt)(UINT result);
STDMETHOD(OutputsBSTR)(BSTR * result);
STDMETHOD(OutputsI4)(LONG * result);
STDMETHOD(OutputsUI1)(BYTE * result);
STDMETHOD(OutputsI2)(SHORT * result);
STDMETHOD(OutputsR4)(FLOAT * result);
STDMETHOD(OutputsR8)(DOUBLE * result);
STDMETHOD(OutputsBool)(VARIANT_BOOL * result);
STDMETHOD(OutputsIDispatch)(IDispatch * * result);
STDMETHOD(OutputsError)(SCODE * result);
STDMETHOD(OutputsDate)(DATE * result);
STDMETHOD(OutputsIUnknown)(IUnknown * * result);
STDMETHOD(OutputsI1)(unsigned char * result);
STDMETHOD(OutputsUI2)(USHORT * result);
STDMETHOD(OutputsUI4)(ULONG * result);
STDMETHOD(InOutsBSTR)(BSTR * result);
STDMETHOD(InOutsI4)(LONG * result);
STDMETHOD(InOutsUI1)(BYTE * result);
STDMETHOD(InOutsI2)(SHORT * result);
STDMETHOD(InOutsR4)(FLOAT * result);
STDMETHOD(InOutsR8)(DOUBLE * result);
STDMETHOD(InOutsBool)(VARIANT_BOOL * result);
STDMETHOD(InOutsIDispatch)(IDispatch * * result);
STDMETHOD(InOutsError)(SCODE * result);
STDMETHOD(InOutsDate)(DATE * result);
STDMETHOD(InOutsIUnknown)(IUnknown * * result);
STDMETHOD(InOutsI1)(unsigned char * result);
STDMETHOD(InOutsUI2)(USHORT * result);
STDMETHOD(InOutsUI4)(ULONG * result);
STDMETHOD(OneParameterWithReturn)(LONG input, LONG * result);
STDMETHOD(StringInputAndReturn)(BSTR str, BSTR * result);
STDMETHOD(IDispatchInputAndReturn)(IDispatch * input, IDispatch** result);
STDMETHOD(TwoParameters)(LONG one, LONG two);
STDMETHOD(TwelveInParameters)(LONG one, LONG two, LONG three, LONG four,
LONG five, LONG six, LONG seven, LONG eight,
LONG nine, LONG ten, LONG eleven,
LONG twelve);
STDMETHOD(TwelveOutParameters)(LONG * one, LONG * two, LONG * three,
LONG * four, LONG * five, LONG * six,
LONG * seven, LONG * eight, LONG * nine,
LONG * ten, LONG * eleven, LONG * twelve);
STDMETHOD(TwelveStrings)(BSTR one, BSTR two, BSTR three, BSTR four,
BSTR five, BSTR six, BSTR seven, BSTR eight,
BSTR nine, BSTR ten, BSTR eleven, BSTR twelve);
STDMETHOD(TwelveOutStrings)(BSTR * one, BSTR * two, BSTR * three,
BSTR * four, BSTR * five, BSTR * six,
BSTR * seven, BSTR * eight, BSTR * nine,
BSTR * ten, BSTR * eleven, BSTR * twelve);
STDMETHOD(TwelveIDispatch)(IDispatch * one, IDispatch * two,
IDispatch * three, IDispatch * four,
IDispatch * five, IDispatch * six,
IDispatch * seven, IDispatch * eight,
IDispatch * nine, IDispatch * ten,
IDispatch * eleven, IDispatch * twelve);
STDMETHOD(TwelveOutIDispatch)(IDispatch * * one, IDispatch * * two,
IDispatch * * three, IDispatch * * four,
IDispatch * * five, IDispatch * * six,
IDispatch * * seven, IDispatch * * eight,
IDispatch * * nine, IDispatch * * ten,
IDispatch * * eleven, IDispatch * * twelve);
STDMETHOD(CreateError)();
};
#endif // !defined(AFX_NSXPCDISPTESTMETHODS_H__A516B1D7_1971_419C_AE35_EDFAC27D1227__INCLUDED_)

View File

@@ -1,23 +0,0 @@
HKCR
{
XPCIDispatchTest.nsXPCDispTestMethods.1 = s 'nsXPCDispTestMethods Class'
{
CLSID = s '{745D1149-9F46-418C-B176-71EAA98974BA}'
}
XPCIDispatchTest.nsXPCDispTestMethods = s 'nsXPCDispTestMethods Class'
{
CLSID = s '{745D1149-9F46-418C-B176-71EAA98974BA}'
}
NoRemove CLSID
{
ForceRemove {745D1149-9F46-418C-B176-71EAA98974BA} = s 'nsXPCDispTestMethods Class'
{
ProgID = s 'XPCIDispatchTest.nsXPCDispTestMethods.1'
VersionIndependentProgID = s 'XPCIDispatchTest.nsXPCDispTestMethods'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'both'
}
}
}
}

View File

@@ -1,23 +0,0 @@
// nsXPCDispTestNoIDispatch.cpp : Implementation of CXPCIDispatchTestApp and DLL registration.
#include "stdafx.h"
#include "XPCIDispatchTest.h"
#include "nsXPCDispTestNoIDispatch.h"
/////////////////////////////////////////////////////////////////////////////
//
STDMETHODIMP nsXPCDispTestNoIDispatch::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_nsIXPCDispTestNoIDispatch,
};
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}

View File

@@ -1,41 +0,0 @@
// nsXPCDispTestNoIDispatch.h: Definition of the nsXPCDispTestNoIDispatch class
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_NSXPCDISPTESTNOIDISPATCH_H__E4B74F67_BA6B_4654_8674_E60E487129F7__INCLUDED_)
#define AFX_NSXPCDISPTESTNOIDISPATCH_H__E4B74F67_BA6B_4654_8674_E60E487129F7__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// nsXPCDispTestNoIDispatch
class nsXPCDispTestNoIDispatch :
public nsIXPCDispTestNoIDispatch,
public ISupportErrorInfo,
public CComObjectRoot,
public CComCoClass<nsXPCDispTestNoIDispatch,&CLSID_nsXPCDispTestNoIDispatch>
{
public:
nsXPCDispTestNoIDispatch() {}
BEGIN_COM_MAP(nsXPCDispTestNoIDispatch)
COM_INTERFACE_ENTRY(nsIXPCDispTestNoIDispatch)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
//DECLARE_NOT_AGGREGATABLE(nsXPCDispTestNoIDispatch)
// Remove the comment from the line above if you don't want your object to
// support aggregation.
DECLARE_REGISTRY_RESOURCEID(IDR_nsXPCDispTestNoIDispatch)
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// nsIXPCDispTestNoIDispatch
public:
};
#endif // !defined(AFX_NSXPCDISPTESTNOIDISPATCH_H__E4B74F67_BA6B_4654_8674_E60E487129F7__INCLUDED_)

View File

@@ -1,23 +0,0 @@
HKCR
{
XPCIDispatchTest.nsXPCDispTestNoIDispatch.1 = s 'nsXPCDispTestNoIDispatch Class'
{
CLSID = s '{7414404F-A4CC-4E3C-9B32-BB20CB22F541}'
}
XPCIDispatchTest.nsXPCDispTestNoIDispatch = s 'nsXPCDispTestNoIDispatch Class'
{
CLSID = s '{7414404F-A4CC-4E3C-9B32-BB20CB22F541}'
}
NoRemove CLSID
{
ForceRemove {7414404F-A4CC-4E3C-9B32-BB20CB22F541} = s 'nsXPCDispTestNoIDispatch Class'
{
ProgID = s 'XPCIDispatchTest.nsXPCDispTestNoIDispatch.1'
VersionIndependentProgID = s 'XPCIDispatchTest.nsXPCDispTestNoIDispatch'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'both'
}
}
}
}

View File

@@ -1,256 +0,0 @@
// nsXPCDispTestProperties.cpp : Implementation of CXPCIDispatchTestApp and DLL registration.
#include "stdafx.h"
#include "XPCIDispatchTest.h"
#include "nsXPCDispTestProperties.h"
const long PARAMETERIZED_PROPERTY_COUNT = 5;
/////////////////////////////////////////////////////////////////////////////
//
STDMETHODIMP nsXPCDispTestProperties::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_nsIXPCDispTestProperties,
};
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
nsXPCDispTestProperties::nsXPCDispTestProperties() :
mChar('a'),
mBOOL(FALSE),
mSCode(0),
mDATE(0),
mDouble(0.0),
mFloat(0.0f),
mLong(0),
mShort(0),
mParameterizedProperty(new long[PARAMETERIZED_PROPERTY_COUNT])
{
mCURRENCY.int64 = 0;
CComBSTR string("Initial value");
mBSTR = string.Detach();
for (long index = 0; index < PARAMETERIZED_PROPERTY_COUNT; ++index)
mParameterizedProperty[index] = index + 1;
}
nsXPCDispTestProperties::~nsXPCDispTestProperties()
{
delete [] mParameterizedProperty;
}
STDMETHODIMP nsXPCDispTestProperties::get_Short(short *pVal)
{
*pVal = mShort;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_Short(short newVal)
{
mShort = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_Long(long *pVal)
{
*pVal = mLong;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_Long(long newVal)
{
mLong = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_Float(float *pVal)
{
*pVal = mFloat;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_Float(float newVal)
{
mFloat = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_Double(double *pVal)
{
*pVal = mDouble;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_Double(double newVal)
{
mDouble = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_Currency(CURRENCY *pVal)
{
*pVal = mCURRENCY;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_Currency(CURRENCY newVal)
{
mCURRENCY = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_Date(DATE *pVal)
{
*pVal = mDATE;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_Date(DATE newVal)
{
mDATE = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_String(BSTR *pVal)
{
*pVal = mBSTR.Copy();
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_String(BSTR newVal)
{
mBSTR = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_DispatchPtr(IDispatch **pVal)
{
mIDispatch.CopyTo(pVal);
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_DispatchPtr(IDispatch *newVal)
{
mIDispatch = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_SCode(SCODE *pVal)
{
*pVal = mSCode;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_SCode(SCODE newVal)
{
mSCode = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_Boolean(BOOL *pVal)
{
*pVal = mBOOL;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_Boolean(BOOL newVal)
{
mBOOL = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_Variant(VARIANT *pVal)
{
::VariantCopy(pVal, &mVariant);
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_Variant(VARIANT newVal)
{
mVariant = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_COMPtr(IUnknown **pVal)
{
mIUnknown.CopyTo(pVal);
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_COMPtr(IUnknown *newVal)
{
mIUnknown = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_Char(unsigned char *pVal)
{
*pVal = mChar;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_Char(unsigned char newVal)
{
mChar = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_ParameterizedProperty(long aIndex, long *pVal)
{
if (aIndex < 0 || aIndex >= PARAMETERIZED_PROPERTY_COUNT)
return E_FAIL;
*pVal = mParameterizedProperty[aIndex];
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::put_ParameterizedProperty(long aIndex, long newVal)
{
if (aIndex < 0 || aIndex >= PARAMETERIZED_PROPERTY_COUNT)
return E_FAIL;
mParameterizedProperty[aIndex] = newVal;
return S_OK;
}
STDMETHODIMP nsXPCDispTestProperties::get_ParameterizedPropertyCount(long *pVal)
{
*pVal = PARAMETERIZED_PROPERTY_COUNT;
return S_OK;
}

View File

@@ -1,88 +0,0 @@
// nsXPCDispTestProperties.h: Definition of the nsXPCDispTestProperties class
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_NSXPCDISPTESTPROPERTIES_H__9E10C7AC_36AF_4A3A_91C7_2CFB9EB166A5__INCLUDED_)
#define AFX_NSXPCDISPTESTPROPERTIES_H__9E10C7AC_36AF_4A3A_91C7_2CFB9EB166A5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// nsXPCDispTestProperties
class nsXPCDispTestProperties :
public IDispatchImpl<nsIXPCDispTestProperties, &IID_nsIXPCDispTestProperties, &LIBID_IDispatchTestLib>,
public ISupportErrorInfo,
public CComObjectRoot,
public CComCoClass<nsXPCDispTestProperties,&CLSID_nsXPCDispTestProperties>
{
public:
nsXPCDispTestProperties();
virtual ~nsXPCDispTestProperties();
BEGIN_CATEGORY_MAP(nsXPCDispTestProperties)
IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
END_CATEGORY_MAP()
BEGIN_COM_MAP(nsXPCDispTestProperties)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(nsIXPCDispTestProperties)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
DECLARE_NOT_AGGREGATABLE(nsXPCDispTestProperties)
DECLARE_REGISTRY_RESOURCEID(IDR_nsXPCDispTestProperties)
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// nsIXPCDispTestProperties
public:
STDMETHOD(get_ParameterizedPropertyCount)(/*[out, retval]*/ long *pVal);
STDMETHOD(get_ParameterizedProperty)(/*[in]*/long aIndex, /*[out, retval]*/ long *pVal);
STDMETHOD(put_ParameterizedProperty)(/*[in]*/long aIndex, /*[in]*/ long newVal);
STDMETHOD(get_Char)(/*[out, retval]*/ unsigned char *pVal);
STDMETHOD(put_Char)(/*[in]*/ unsigned char newVal);
STDMETHOD(get_COMPtr)(/*[out, retval]*/ IUnknown* *pVal);
STDMETHOD(put_COMPtr)(/*[in]*/ IUnknown* newVal);
STDMETHOD(get_Variant)(/*[out, retval]*/ VARIANT *pVal);
STDMETHOD(put_Variant)(/*[in]*/ VARIANT newVal);
STDMETHOD(get_Boolean)(/*[out, retval]*/ BOOL *pVal);
STDMETHOD(put_Boolean)(/*[in]*/ BOOL newVal);
STDMETHOD(get_SCode)(/*[out, retval]*/ SCODE *pVal);
STDMETHOD(put_SCode)(/*[in]*/ SCODE newVal);
STDMETHOD(get_DispatchPtr)(/*[out, retval]*/ IDispatch* *pVal);
STDMETHOD(put_DispatchPtr)(/*[in]*/ IDispatch* newVal);
STDMETHOD(get_String)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(put_String)(/*[in]*/ BSTR newVal);
STDMETHOD(get_Date)(/*[out, retval]*/ DATE *pVal);
STDMETHOD(put_Date)(/*[in]*/ DATE newVal);
STDMETHOD(get_Currency)(/*[out, retval]*/ CURRENCY *pVal);
STDMETHOD(put_Currency)(/*[in]*/ CURRENCY newVal);
STDMETHOD(get_Double)(/*[out, retval]*/ double *pVal);
STDMETHOD(put_Double)(/*[in]*/ double newVal);
STDMETHOD(get_Float)(/*[out, retval]*/ float *pVal);
STDMETHOD(put_Float)(/*[in]*/ float newVal);
STDMETHOD(get_Long)(/*[out, retval]*/ long *pVal);
STDMETHOD(put_Long)(/*[in]*/ long newVal);
STDMETHOD(get_Short)(/*[out, retval]*/ short *pVal);
STDMETHOD(put_Short)(/*[in]*/ short newVal);
private:
unsigned char mChar;
CComPtr<IUnknown> mIUnknown;
CComVariant mVariant;
BOOL mBOOL;
SCODE mSCode;
CComPtr<IDispatch> mIDispatch;
CComBSTR mBSTR;
DATE mDATE;
CURRENCY mCURRENCY;
double mDouble;
float mFloat;
long mLong;
short mShort;
long * mParameterizedProperty;
};
#endif // !defined(AFX_NSXPCDISPTESTPROPERTIES_H__9E10C7AC_36AF_4A3A_91C7_2CFB9EB166A5__INCLUDED_)

View File

@@ -1,23 +0,0 @@
HKCR
{
XPCIDispatchTest.nsXPCDispTestProperties.1 = s 'nsXPCDispTestProperties Class'
{
CLSID = s '{D8B4265B-1768-4CA9-A285-7CCAEEB51C74}'
}
XPCIDispatchTest.nsXPCDispTestProperties = s 'nsXPCDispTestProperties Class'
{
CLSID = s '{D8B4265B-1768-4CA9-A285-7CCAEEB51C74}'
}
NoRemove CLSID
{
ForceRemove {D8B4265B-1768-4CA9-A285-7CCAEEB51C74} = s 'nsXPCDispTestProperties Class'
{
ProgID = s 'XPCIDispatchTest.nsXPCDispTestProperties.1'
VersionIndependentProgID = s 'XPCIDispatchTest.nsXPCDispTestProperties'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'both'
}
}
}
}

View File

@@ -1,23 +0,0 @@
// nsXPCDispTestScriptOff.cpp : Implementation of CXPCIDispatchTestApp and DLL registration.
#include "stdafx.h"
#include "XPCIDispatchTest.h"
#include "nsXPCDispTestScriptOff.h"
/////////////////////////////////////////////////////////////////////////////
//
STDMETHODIMP nsXPCDispTestScriptOff::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_nsIXPCDispTestScriptOff,
};
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}

View File

@@ -1,43 +0,0 @@
// nsXPCDispTestScriptOff.h: Definition of the nsXPCDispTestScriptOff class
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_NSXPCDISPTESTSCRIPTOFF_H__EEC88DE0_F502_4893_9918_4E435DBC9815__INCLUDED_)
#define AFX_NSXPCDISPTESTSCRIPTOFF_H__EEC88DE0_F502_4893_9918_4E435DBC9815__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "resource.h" // main symbols
#include <ATLCTL.H>
/////////////////////////////////////////////////////////////////////////////
// nsXPCDispTestScriptOff
class nsXPCDispTestScriptOff :
public IDispatchImpl<nsIXPCDispTestScriptOff, &IID_nsIXPCDispTestScriptOff, &LIBID_IDispatchTestLib>,
public ISupportErrorInfo,
public CComObjectRoot,
public CComCoClass<nsXPCDispTestScriptOff,&CLSID_nsXPCDispTestScriptOff>,
public IObjectSafetyImpl<nsXPCDispTestScriptOff, 0>
{
public:
nsXPCDispTestScriptOff() {}
BEGIN_COM_MAP(nsXPCDispTestScriptOff)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(nsIXPCDispTestScriptOff)
COM_INTERFACE_ENTRY(IObjectSafety)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
DECLARE_NOT_AGGREGATABLE(nsXPCDispTestScriptOff)
DECLARE_REGISTRY_RESOURCEID(IDR_nsXPCDispTestScriptOff)
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// nsIXPCDispTestScriptOff
public:
};
#endif // !defined(AFX_NSXPCDISPTESTSCRIPTOFF_H__EEC88DE0_F502_4893_9918_4E435DBC9815__INCLUDED_)

View File

@@ -1,23 +0,0 @@
HKCR
{
XPCIDispatchTest.nsXPCDispTestScriptOff.1 = s 'nsXPCDispTestScriptOff Class'
{
CLSID = s '{959CD122-9826-4757-BA09-DE327D55F9E7}'
}
XPCIDispatchTest.nsXPCDispTestScriptOff = s 'nsXPCDispTestScriptOff Class'
{
CLSID = s '{959CD122-9826-4757-BA09-DE327D55F9E7}'
}
NoRemove CLSID
{
ForceRemove {959CD122-9826-4757-BA09-DE327D55F9E7} = s 'nsXPCDispTestScriptOff Class'
{
ProgID = s 'XPCIDispatchTest.nsXPCDispTestScriptOff.1'
VersionIndependentProgID = s 'XPCIDispatchTest.nsXPCDispTestScriptOff'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'both'
}
}
}
}

View File

@@ -1,29 +0,0 @@
// nsXPCDispTestScriptOn.cpp : Implementation of CXPCIDispatchTestApp and DLL registration.
#include "stdafx.h"
#include "XPCIDispatchTest.h"
#include "nsXPCDispTestScriptOn.h"
/////////////////////////////////////////////////////////////////////////////
//
STDMETHODIMP nsXPCDispTestScriptOn::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_nsIXPCDispTestScriptOn,
};
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
nsXPCDispTestScriptOn::nsXPCDispTestScriptOn()
{
m_dwCurrentSafety = INTERFACESAFE_FOR_UNTRUSTED_CALLER |
INTERFACESAFE_FOR_UNTRUSTED_DATA;
}

View File

@@ -1,45 +0,0 @@
// nsXPCDispTestScriptOn.h: Definition of the nsXPCDispTestScriptOn class
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_NSXPCDISPTESTSCRIPTON_H__C037D462_C403_48FF_A02F_6C36544F0833__INCLUDED_)
#define AFX_NSXPCDISPTESTSCRIPTON_H__C037D462_C403_48FF_A02F_6C36544F0833__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "resource.h" // main symbols
#include <ATLCTL.H>
/////////////////////////////////////////////////////////////////////////////
// nsXPCDispTestScriptOn
class nsXPCDispTestScriptOn :
public IDispatchImpl<nsIXPCDispTestScriptOn, &IID_nsIXPCDispTestScriptOn, &LIBID_IDispatchTestLib>,
public ISupportErrorInfo,
public CComObjectRoot,
public CComCoClass<nsXPCDispTestScriptOn,&CLSID_nsXPCDispTestScriptOn>,
public IObjectSafetyImpl<nsXPCDispTestScriptOn,
INTERFACESAFE_FOR_UNTRUSTED_CALLER |
INTERFACESAFE_FOR_UNTRUSTED_DATA>
{
public:
nsXPCDispTestScriptOn();
BEGIN_COM_MAP(nsXPCDispTestScriptOn)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(nsIXPCDispTestScriptOn)
COM_INTERFACE_ENTRY(IObjectSafety)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
DECLARE_NOT_AGGREGATABLE(nsXPCDispTestScriptOn)
DECLARE_REGISTRY_RESOURCEID(IDR_nsXPCDispTestScriptOn)
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// nsIXPCDispTestScriptOn
public:
};
#endif // !defined(AFX_NSXPCDISPTESTSCRIPTON_H__C037D462_C403_48FF_A02F_6C36544F0833__INCLUDED_)

View File

@@ -1,23 +0,0 @@
HKCR
{
XPCIDispatchTest.nsXPCDispTestScriptOn.1 = s 'nsXPCDispTestScriptOn Class'
{
CLSID = s '{2A06373F-3E61-4882-A3D7-A104F70B09ED}'
}
XPCIDispatchTest.nsXPCDispTestScriptOn = s 'nsXPCDispTestScriptOn Class'
{
CLSID = s '{2A06373F-3E61-4882-A3D7-A104F70B09ED}'
}
NoRemove CLSID
{
ForceRemove {2A06373F-3E61-4882-A3D7-A104F70B09ED} = s 'nsXPCDispTestScriptOn Class'
{
ProgID = s 'XPCIDispatchTest.nsXPCDispTestScriptOn.1'
VersionIndependentProgID = s 'XPCIDispatchTest.nsXPCDispTestScriptOn'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'both'
}
}
}
}

View File

@@ -1,177 +0,0 @@
// nsXPCDispTestWrappedJS.cpp : Implementation of CXPCIDispatchTestApp and DLL registration.
#include "stdafx.h"
#include "XPCIDispatchTest.h"
#include "nsXPCDispTestWrappedJS.h"
#include <string>
#include <sstream>
/////////////////////////////////////////////////////////////////////////////
//
STDMETHODIMP nsXPCDispTestWrappedJS::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_nsIXPCDispTestWrappedJS,
};
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
struct TestData
{
typedef bool (*CompFunc)(const _variant_t & left, const _variant_t & right);
TestData(const char * name, const _variant_t & value, CompFunc cf) :
mName(name), mValue(value), mCompFunc(cf) {}
const char * mName;
_variant_t mValue;
CompFunc mCompFunc;
};
bool CompareVariant(const _variant_t & left, const _variant_t & right)
{
return left == right;
}
// These should be a template but VC++6 is brain dead in this area
#define CompareFunction(type) \
bool CompareVariant##type(const _variant_t & left, const _variant_t & right) \
{ \
return static_cast<type>(left) == static_cast<type>(right); \
}
CompareFunction(long);
CompareFunction(float);
CompareFunction(double);
CompareFunction(_bstr_t);
DISPID GetIDsOfNames(IDispatch * pIDispatch , char const * i_Method)
{
DISPID dispid;
CComBSTR method(i_Method);
OLECHAR * pMethod = method;
HRESULT hresult = pIDispatch->GetIDsOfNames(
IID_NULL,
&pMethod,
1,
LOCALE_SYSTEM_DEFAULT,
&dispid);
if (!SUCCEEDED(hresult))
{
dispid = 0;
}
return dispid;
}
namespace
{
inline
_bstr_t ConvertVariantFromBSTR(_variant_t & variant)
{
VARIANT temp = variant;
if (SUCCEEDED(VariantChangeType(&temp, &temp, 0, VT_BSTR)))
{
variant.Attach(temp);
return static_cast<_bstr_t>(variant);
}
return "**Type Conversion failed";
}
std::string DispInvoke(IDispatch * obj, const TestData & testData)
{
// Perform a put on the property
ITypeInfo * pTypeInfo;
obj->GetTypeInfo(0, LOCALE_SYSTEM_DEFAULT, &pTypeInfo);
DISPID dispID = ::GetIDsOfNames(obj, testData.mName);
DISPPARAMS dispParams;
dispParams.cArgs = 1;
dispParams.rgvarg = const_cast<VARIANT*>(&reinterpret_cast<const VARIANT&>(testData.mValue));
dispParams.cNamedArgs = 1;
DISPID propPut = DISPID_PROPERTYPUT;
dispParams.rgdispidNamedArgs = &propPut;
_variant_t result1;
HRESULT hResult = obj->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dispParams, &result1, 0, 0);
if (FAILED(hResult))
{
std::ostringstream msg;
msg << "IDispatch::Invoke on " << testData.mName << " failed to set property with result " << hResult;
return msg.str();
}
dispParams.cArgs = 1;
dispParams.rgvarg = const_cast<VARIANT*>(&reinterpret_cast<const VARIANT&>(testData.mValue));
dispParams.cNamedArgs = 0;
dispParams.rgdispidNamedArgs = 0;
_variant_t result2;
hResult = obj->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, &dispParams, &result2, 0, 0);
if (FAILED(hResult))
{
std::ostringstream msg;
msg << "IDispatch::Invoke on " << testData.mName << " failed to retrieve property with result " << hResult;
return msg.str();
}
if (!testData.mCompFunc(result2,testData.mValue))
{
std::ostringstream msg;
VARIANT temp = testData.mValue;
char const * const desired = SUCCEEDED(VariantChangeType(&temp, &temp, 0, VT_BSTR)) ? 0 : "**Conversion Failed";
char const * const actual = SUCCEEDED(VariantChangeType(&result2, &result2, 0, VT_BSTR)) ? 0 : "**Conversion Failed";
msg << testData.mName << " ["
<< (desired ? desired : static_cast<char const *>(static_cast<_bstr_t>(testData.mValue))) << "] ["
<< (actual ? actual : static_cast<char const *>(static_cast<_bstr_t>(result2))) << "]";
return msg.str();
}
return std::string();
}
}
STDMETHODIMP nsXPCDispTestWrappedJS::TestParamTypes(IDispatch *obj, BSTR *errMsg)
{
CComPtr<IDispatch> ptr;
CComBSTR progID("XPCIDispatchTest.nsXPCDispSimple.1");
ptr.CoCreateInstance(progID);
_variant_t dispatchPtr;
dispatchPtr = static_cast<IDispatch*>(ptr);
CURRENCY currency;
currency.int64 = 55555;
_variant_t date(3000.0, VT_DATE);
_variant_t nullVariant;
nullVariant.ChangeType(VT_NULL);
const TestData tests[] =
{
TestData("Boolean", _variant_t(true), CompareVariant),
TestData("Short", _variant_t(short(4200)), reinterpret_cast<TestData::CompFunc>(CompareVariantlong)),
TestData("Long", _variant_t(long(-42000000)), CompareVariantlong),
TestData("Float", _variant_t(float(4.5)), CompareVariantfloat),
TestData("Double", _variant_t(-11111.11), CompareVariant),
// TestData("Currency", _variant_t(currency), CompareVariantdouble),
TestData("Date", date, CompareVariant_bstr_t),
TestData("String", _variant_t("A String"), CompareVariant),
TestData("DispatchPtr", dispatchPtr, CompareVariant),
// TestData("SCode", _variant_t(long(5), VT_ERROR), CompareVariant_bstr_t),
TestData("Variant", nullVariant, CompareVariant),
TestData("Char", _variant_t(BYTE('x')), CompareVariant_bstr_t)
};
std::string errors;
for (size_t index = 0; index < sizeof(tests) / sizeof(TestData); ++index)
{
std::string msg = DispInvoke(obj, tests[index]);
if (!msg.empty())
{
errors += msg;
errors += "\r\n";
}
}
CComBSTR errorMsg(errors.c_str());
*errMsg = errorMsg.Detach();
return S_OK;
}

View File

@@ -1,50 +0,0 @@
// nsXPCDispTestWrappedJS.h: Definition of the nsXPCDispTestWrappedJS class
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_NSXPCDISPTESTWRAPPEDJS_H__DAAB3C99_1894_40C2_B12B_A360739F8977__INCLUDED_)
#define AFX_NSXPCDISPTESTWRAPPEDJS_H__DAAB3C99_1894_40C2_B12B_A360739F8977__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// nsXPCDispTestWrappedJS
class nsXPCDispTestWrappedJS :
public IDispatchImpl<nsIXPCDispTestWrappedJS, &IID_nsIXPCDispTestWrappedJS, &LIBID_IDispatchTestLib>,
public ISupportErrorInfo,
public CComObjectRoot,
public CComCoClass<nsXPCDispTestWrappedJS,&CLSID_nsXPCDispTestWrappedJS>
{
public:
nsXPCDispTestWrappedJS() {}
BEGIN_CATEGORY_MAP(nsXPCDispTestWrappedJS)
IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
END_CATEGORY_MAP()
BEGIN_COM_MAP(nsXPCDispTestWrappedJS)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(nsIXPCDispTestWrappedJS)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
DECLARE_NOT_AGGREGATABLE(nsXPCDispTestWrappedJS)
DECLARE_REGISTRY_RESOURCEID(IDR_nsXPCDispTestWrappedJS)
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// nsIXPCDispTestWrappedJS
public:
/**
* This tests interacting with JS Objects via IDispatch
* @param obj the object being tested
* @param errMsg string receiving any error message, blank if no error
*/
STDMETHOD(TestParamTypes)(/*[in]*/ IDispatch * obj,
/*[out]*/BSTR * errMsg);
};
#endif // !defined(AFX_NSXPCDISPTESTWRAPPEDJS_H__DAAB3C99_1894_40C2_B12B_A360739F8977__INCLUDED_)

View File

@@ -1,23 +0,0 @@
HKCR
{
XPCIDispatchTest.nsXPCDispTestWrappedJS.1 = s 'nsXPCDispTestWrappedJS Class'
{
CLSID = s '{EAEE6BB2-C005-4B91-BCA7-6613236F6F69}'
}
XPCIDispatchTest.nsXPCDispTestWrappedJS = s 'nsXPCDispTestWrappedJS Class'
{
CLSID = s '{EAEE6BB2-C005-4B91-BCA7-6613236F6F69}'
}
NoRemove CLSID
{
ForceRemove {EAEE6BB2-C005-4B91-BCA7-6613236F6F69} = s 'nsXPCDispTestWrappedJS Class'
{
ProgID = s 'XPCIDispatchTest.nsXPCDispTestWrappedJS.1'
VersionIndependentProgID = s 'XPCIDispatchTest.nsXPCDispTestWrappedJS'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'both'
}
}
}
}

View File

@@ -1,36 +0,0 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by XPCIDispatchTest.rc
//
#define IDS_PROJNAME 100
#define IDS_NSXPCDISPTTESTMETHODS_DESC 101
#define IDR_nsXPCDisptTestMethods 102
#define IDS_NSXPCDISPTESTMETHODS_DESC 103
#define IDR_nsXPCDispTestMethods 104
#define IDS_NSXPCDISPSIMPLE_DESC 105
#define IDR_nsXPCDispSimple 106
#define IDS_NSXPCDISPTESTNOIDISPATCH_DESC 107
#define IDR_nsXPCDispTestNoIDispatch 108
#define IDS_NSXPCDISPTESTNOSCRIPT_DESC 109
#define IDR_nsXPCDispTestNoScript 110
#define IDS_NSXPCDISPTESTPROPERTIES_DESC 111
#define IDR_nsXPCDispTestProperties 112
#define IDS_NSXPCDISPTESTARRAYS_DESC 113
#define IDR_nsXPCDispTestArrays 114
#define IDS_NSXPCDISPTESTSCRIPTON_DESC 115
#define IDR_nsXPCDispTestScriptOn 116
#define IDS_NSXPCDISPTESTSCRIPTOFF_DESC 117
#define IDR_nsXPCDispTestScriptOff 118
#define IDS_NSXPCDISPTESTWRAPPEDJS_DESC 119
#define IDR_nsXPCDispTestWrappedJS 120
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 204
#define _APS_NEXT_COMMAND_VALUE 32768
#define _APS_NEXT_CONTROL_VALUE 201
#define _APS_NEXT_SYMED_VALUE 121
#endif
#endif

View File

@@ -1,54 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the IDispatch implementation for XPConnect
*
* The Initial Developer of the Original Code is
* David Bradley.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Verify that we can access but not overwrite the values of read-only
* attributes.
*/
test();
function test()
{
printStatus("Testing arrays");
var obj = COMObject(CLSID_nsXPCDispTestArrays);
var anArray = [ 0, 1, 2, 3];
obj.TakesSafeArray(anArray);
var strArray = [ "0", "1", "2", "3"];
obj.TakesSafeArrayBSTR(strArray);
return 0;
}

View File

@@ -1,150 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the IDispatch implementation for XPConnect
*
* The Initial Developer of the Original Code is
* David Bradley.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* \file XPCIDispatchAttributeTests.js
* Test IDispatch properties and also type conversion
*/
try
{
// Test object used to test IDispatch property.
testObject = { one : 1, two : 2, three : 'three' };
test();
}
catch (e)
{
reportFailure("Unhandled exception encountered: " + e.toString());
}
/**
* Main function to perform test
*/
function test()
{
printStatus("Read-Write Attributes");
/*
* These values come from xpctest_attributes.idl and xpctest_attributes.cpp
*/
o = COMObject(CLSID_nsXPCDispTestProperties);
// Check the class an interface to make sure they're ok
reportCompare(
"object",
typeof o,
"typeof COMObject(CLSID_nsXPCDispTestProperties)");
// Make sure we can read the values
testProperty("o.Boolean", ["true", "1","testObject", "'T'", "'F'", "'true'","'false'"], false);
testProperty("o.Char", ["32"], true);
testProperty("o.COMPtr", ["0"], true);
testProperty("o.Currency", ["0", "0.5", "10000.00"], true);
testProperty("o.Date", ["'04/01/03'"], false);
testProperty("o.DispatchPtr", ["testObject"], false);
testProperty("o.Double", ["5.555555555555555555555", "5.555555555555555555555", "5", "-5"], true);
testProperty("o.Float", ["-5.55555555", "5.5555555", "5", "-5"], true);
testProperty("o.Long", ["-5", "1073741823", "-1073741824", "1073741824", "-1073741825", "5.5"], true);
testProperty("o.SCode", ["5"], true);
testProperty("o.Short", ["5", "-5", "32767", "-32768"], true);
testProperty("o.String", ["'A String'", "'c'", "5", "true"], false);
testProperty("o.Variant", ["'A Variant String'", "testObject", "10", "5.5"], false);
// Parameterized property tests
for (index = 0; index < o.ParameterizedPropertyCount; ++index)
compareExpression(
"o.ParameterizedProperty(index)",
index + 1,
"Reading initial value from parameterized property " + index);
for (index = 0; index < o.ParameterizedPropertyCount; ++index)
compareExpression(
"o.ParameterizedProperty(index) = index + 5",
index + 5,
"Assigning parameterized property " + index);
for (index = 0; index < o.ParameterizedPropertyCount; ++index)
compareExpression(
"o.ParameterizedProperty(index)",
index + 5,
"Reading new value from parameterized property " + index);
}
/**
* Tests retrieving a value from a property and setting multiple values on
* the property
*/
function testProperty(propertyExpression, values, tryString)
{
print(propertyExpression);
try
{
reportCompare(
eval(propertyExpression),
eval(propertyExpression),
propertyExpression);
}
catch (e)
{
reportFailure("Testing initial value of " + propertyExpression + " Exception: " + e.toString());
}
for (i = 0; i < values.length; ++i)
{
var value = values[i];
var expression = propertyExpression + "=" + value;
print(expression);
try
{
reportCompare(
eval(expression),
eval(value),
expression);
if (tryString)
{
expression = propertyExpression + "='" + value + "'";
print(expression);
reportCompare(
eval(expression),
eval("'" + value + "'"),
expression);
}
}
catch (e)
{
reportFailure("Testing assignment: " + expression + " Exception: " + e.toString());
}
}
}

View File

@@ -1,122 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the IDispatch implementation for XPConnect
*
* The Initial Developer of the Original Code is
* David Bradley.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Verify that we can access but not overwrite the values of read-only
* attributes.
*/
test();
function testInstantiate(name, id, scriptable, methods)
{
var IDISPATCH_TEXT = "[xpconnect wrapped IDispatch";
var obj = COMObject(id);
var value = obj.toString().substr(0, IDISPATCH_TEXT.length);
reportCompare(
IDISPATCH_TEXT,
value,
"var obj = COMObject(" + id + ");");
try
{
obj = COMObject(id);
}
catch (e)
{
if (scriptable)
{
reportFailure("COMObject('" + id + "') generated an exception");
}
return;
}
value = obj.toString().substr(0, IDISPATCH_TEXT.length);
reportCompare(
scriptable ? IDISPATCH_TEXT : undefined,
scriptable ? value : obj,
"var obj = COMObject(" + id + ");");
}
function testEnumeration(compInfo)
{
var obj = COMObject(compInfo.cid);
compareObject(obj, compInfo, "Enumeration Test");
}
function test()
{
try
{
printStatus("Instantiation Tests - " + objectsDesc.length + " objects to test");
for (index = 0; index < objectsDesc.length; ++index)
{
compInfo = objectsDesc[index];
printStatus("Testing " + compInfo.name);
testInstantiate(compInfo.name, compInfo.cid, compInfo.scriptable);
testInstantiate(compInfo.name, compInfo.progid, compInfo.scriptable);
}
// Test a non-existant COM object
var obj;
try
{
obj = COMObject("dwbnonexistantobject");
printFailure("var obj = COMObject('dwbnonexistantobject'); did not throw an exception");
}
catch (e)
{
}
try
{
obj = COMObject("dwbnonexistantobject");
printFailure("obj = COMObject('dwbnonexistantobject'); did not throw an exception");
}
catch (e)
{
}
printStatus("Enumeration Tests - testing " + objectsDesc.length + " objects");
for (var index = 0; index < objectsDesc.length; ++index)
{
printStatus("Enumerating " + objectsDesc[index].name);
testEnumeration(objectsDesc[index]);
}
}
catch (e)
{
reportFailure("Unhandled exception occured:" + e.toString());
}
}

View File

@@ -1,58 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the IDispatch implementation for XPConnect
*
* The Initial Developer of the Original Code is
* David Bradley.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Make repeated calls so GC kicks in and we can check for memory leaks.
*/
test();
function test()
{
printStatus("Stress testing");
for (index = 0; index < 10000; ++index)
{
for (x = 0; x < objectsDesc.length; ++x)
{
var obj = COMObject(objectsDesc[x].cid);
for (prop in obj)
{
print(index + ":" +objectsDesc[x].name + ":" + prop);
}
}
}
}

View File

@@ -1,376 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the IDispatch implementation for XPConnect
*
* The Initial Developer of the Original Code is
* David Bradley.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Verify that we can access but not overwrite the values of read-only
* attributes.
*/
test();
function TestOutMethod(obj, method, value)
{
printDebug("TestOutMethod - " + method);
var x = new Object();
try
{
obj[method](x);
reportCompare(value, x.value, "Testing output parameter: " + method);
}
catch (e)
{
reportFailure("Testing output parameter failed: " + method + ": " + e.toString());
}
}
function TestReturnMethod(obj, method, value)
{
printDebug("TestReturnMethod - " + method);
try
{
reportCompare(value, obj[method](), "Testing output parameter: " + method);
}
catch (e)
{
reportFailure("Testing return value failed: " + method + ": " + e.toString());
}
}
function TestInputMethod(obj, method, value)
{
printDebug("TestInputMethod - " + method);
try
{
obj[method.toLowerCase()](value);
}
catch (e)
{
reportFailure("Testing input parameter failed: " + method + ": " + e.toString());
}
}
function TestInOutMethod(obj, method, inValue, outValue)
{
printDebug("TestInOutMethod - " + method);
try
{
var param = { value : inValue };
obj[method](param);
reportCompare(outValue, param.value, "Testing in/out parameter: " + method);
}
catch (e)
{
reportFailure("Testing in/out parameter failed: " + method + ": " + e.toString());
}
}
function test()
{
printStatus("Testing methods");
var obj = COMObject(CLSID_nsXPCDispTestMethods);
try
{
obj.NoParameters();
}
catch (e)
{
reportFailure("NoParameters failed: " + e.toString());
}
printStatus("Test method - Return values");
TestReturnMethod(obj, "ReturnBSTR", "Boo");
TestReturnMethod(obj, "ReturnI4",99999);
TestReturnMethod(obj, "ReturnUI1", 99);
TestReturnMethod(obj, "ReturnI2",9999);
TestReturnMethod(obj, "ReturnR4",99999.1);
TestReturnMethod(obj, "ReturnR8", 99999999999.99);
TestReturnMethod(obj, "ReturnBool", true);
printStatus("TestReturnMethod - ReturnIDispatch");
compareObject(obj.ReturnIDispatch(), nsXPCDispSimpleDesc, "Test method - Return IDispatch");
var E_FAIL= -2147467259;
TestReturnMethod(obj, "ReturnError", E_FAIL);
TestReturnMethod(obj, "ReturnDate", "5/2/2002");
// TestReturnMethod(obj, ReturnIUnknown(IUnknown * * result)
TestReturnMethod(obj, "ReturnI1", 120);
TestReturnMethod(obj, "ReturnUI2", 9999);
TestReturnMethod(obj, "ReturnUI4", 3000000000);
TestReturnMethod(obj, "ReturnInt", -999999);
TestReturnMethod(obj, "ReturnUInt", 3000000000);
printStatus("Test method - Input params");
TestInputMethod(obj, "TakesBSTR", "TakesBSTR");
TestInputMethod(obj, "TakesI4", 999999);
TestInputMethod(obj, "TakesUI1", 42);
TestInputMethod(obj, "TakesI2", 32000);
TestInputMethod(obj, "TakesR4", 99999.99);
TestInputMethod(obj, "TakesR8", 999999999.99);
TestInputMethod(obj, "TakesBool", true);
var x = { Number : 5, ClassName : "nsXPCDispSimple" };
TestInputMethod(obj, "TakesIDispatch", x);
// This would always fail, type mismatch (no way to indicate this is going
// to an error, and there's no automatic conversion from integers to error
// codes
// TestInputMethod(obj, "TakesError", E_FAIL);
TestInputMethod(obj, "TakesDate", "5/2/2002");
// TestInputMethod(obj, TakesIUnknown, );
TestInputMethod(obj, "TakesI1", 42);
TestInputMethod(obj, "TakesUI2", 50000);
TestInputMethod(obj, "TakesUI4", 4026531840);
TestInputMethod(obj, "TakesInt", -10000000);
TestInputMethod(obj, "TakesUInt", 3758096384);
printStatus("Test method - Output params");
TestOutMethod(obj, "OutputsBSTR", "Boo");
TestOutMethod(obj, "OutputsI4",99999);
TestOutMethod(obj, "OutputsUI1", 99);
TestOutMethod(obj, "OutputsI2",9999);
TestOutMethod(obj, "OutputsR4",999999.1);
TestOutMethod(obj, "OutputsR8", 99999999999.99);
TestOutMethod(obj, "OutputsBool", true);
var outParam = new Object();
obj.OutputsIDispatch(outParam);
compareObject(outParam.value, nsXPCDispSimpleDesc, "Test method - Output params");
TestOutMethod(obj, "OutputsError", E_FAIL);
TestOutMethod(obj, "OutputsDate", "5/2/2002");
// TestOutMethod(obj, OutputsIUnknown(IUnknown * * result)
TestOutMethod(obj, "OutputsI1", 120);
TestOutMethod(obj, "OutputsUI2", 9999);
TestOutMethod(obj, "OutputsUI4", 3000000000);
printStatus("Test method - In/out params");
TestInOutMethod(obj, "InOutsBSTR", "String", "StringAppended");
TestInOutMethod(obj, "InOutsI4", 2000000, -2000000);
TestInOutMethod(obj, "InOutsUI1", 50, 8);
TestInOutMethod(obj, "InOutsI2", -1000, 9000);
TestInOutMethod(obj, "InOutsR4", -2.05, 3.0);
TestInOutMethod(obj, "InOutsR8", -5.5, 49999994.50000005);
TestInOutMethod(obj, "InOutsBool", true, false);
TestInOutMethod(obj, "InOutsBool", false, true);
var inoutParam = { value : {ClassName : "InOutTest", Number : 10 } };
try
{
obj.InOutsIDispatch(inoutParam);
if (inoutParam.value.Number != 15)
reportFailure("Testing in/out parameter failed: IDispatch");
}
catch (e)
{
reportFailure("Testing in/out parameter failed: IDispatch - " + e.toString());
}
// See the TakesError case
//TestInOutMethod(obj, "InOutsError", E_FAIL, E_FAIL + 1);
TestInOutMethod(obj, "InOutsDate", "5/23/2001", "5/24/2001");
//TestInOutMethod(obj, InOutsIUnknown(IUnknown * * result)
TestInOutMethod(obj, "InOutsI1", -42, -41);
TestInOutMethod(obj, "InOutsUI2", 43, 85);
TestInOutMethod(obj, "InOutsUI4", 88, 46);
try
{
reportCompare(obj.OneParameterWithReturn(-20), 22, "Testing OneParameterWithReturn");
}
catch (e)
{
reportFailure("Testing OneParameterWithReturn: " + e.toString());
}
try
{
reportCompare(obj.StringInputAndReturn("A String "), "A String Appended", "Testing StringInputAndReturn");
}
catch (e)
{
reportFailure("Testing StringInputAndReturn: " + e.toString());
}
try
{
var inoutIDispatch = { className : "inouttest", Number : 5 };
var result = obj.IDispatchInputAndReturn(inoutIDispatch);
reportCompare(81, result.Number, "IDispatchInputAndReturn");
}
catch (e)
{
reportFailure("Testing IDispatchInputAndReturn: " + e.toString());
}
try
{
obj.TwoParameters(1, 2);
}
catch (e)
{
reportFailure("Testing TwoParameters: " + e.toString());
}
try
{
obj.TwelveInParameters(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
}
catch (e)
{
reportFailure("Testing TwelveInParameters: " + e.toString());
}
try
{
var out1 = new Object();
var out2 = new Object();
var out3 = new Object();
var out4 = new Object();
var out5 = new Object();
var out6 = new Object();
var out7 = new Object();
var out8 = new Object();
var out9 = new Object();
var out10 = new Object();
var out11 = new Object();
var out12 = new Object();
obj.TwelveOutParameters(out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11, out12);
reportCompare(78, out1.value + out2.value + out3.value + out4.value + out5.value + out6.value + out7.value + out8.value + out9.value + out10.value + out11.value + out12.value, "Testing TwelveOutParameters");
}
catch (e)
{
reportFailure("Testing TwelveOutParameters: " + e.toString());
}
try
{
obj.TwelveStrings("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve");
}
catch (e)
{
reportFailure("Testing TwelveStrings: " + e.toString());
}
try
{
var out1 = new Object();
var out2 = new Object();
var out3 = new Object();
var out4 = new Object();
var out5 = new Object();
var out6 = new Object();
var out7 = new Object();
var out8 = new Object();
var out9 = new Object();
var out10 = new Object();
var out11 = new Object();
var out12 = new Object();
obj.TwelveOutStrings(out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11, out12);
reportCompare(true, out1.value == "one" && out2.value == "two" &&
out3.value == "three" && out4.value == "four" &&
out5.value == "five" && out6.value == "six" &&
out7.value == "seven" && out8.value == "eight" &&
out9.value == "nine" && out10.value == "ten" &&
out11.value == "eleven" && out12.value == "twelve",
"Testing TwelveOutString");
}
catch (e)
{
reportFailure("Testing TwelveOutParameters: " + e.toString());
}
try
{
var out1 = { className : "out1", Number : 5 };
var out2 = { className : "out2", Number : 5 };
var out3 = { className : "out3", Number : 5 };
var out4 = { className : "out4", Number : 5 };
var out5 = { className : "out5", Number : 5 };
var out6 = { className : "out6", Number : 5 };
var out7 = { className : "out7", Number : 5 };
var out8 = { className : "out8", Number : 5 };
var out9 = { className : "out9", Number : 5 };
var out10 = { className : "out10", Number : 5 };
var out11 = { className : "out11", Number : 5 };
var out12 = { className : "out12", Number : 5 };
obj.TwelveIDispatch(out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11, out12);
}
catch (e)
{
reportFailure("Testing TwelveIDispatch: " + e.toString());
}
try
{
var out1 = new Object();
var out2 = new Object();
var out3 = new Object();
var out4 = new Object();
var out5 = new Object();
var out6 = new Object();
var out7 = new Object();
var out8 = new Object();
var out9 = new Object();
var out10 = new Object();
var out11 = new Object();
var out12 = new Object();
obj.TwelveOutIDispatch(out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11, out12);
print("out1.value" + out1.value.Number);
reportCompare(true, out1.value.Number == 5 && out2.value.Number == 5 &&
out3.value.Number == 5 && out4.value.Number == 5 &&
out5.value.Number == 5 && out6.value.Number == 5 &&
out7.value.Number == 5 && out8.value.Number == 5 &&
out9.value.Number == 5 && out10.value.Number == 5 &&
out11.value.Number == 5 && out12.value.Number == 5,
"Testing TwelveOutIDispatch");
compareObject(out1.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out1");
compareObject(out2.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out2");
compareObject(out3.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out3");
compareObject(out4.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out4");
compareObject(out5.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out5");
compareObject(out6.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out6");
compareObject(out7.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out7");
compareObject(out8.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out8");
compareObject(out9.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out9");
compareObject(out10.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out10");
compareObject(out11.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out11");
compareObject(out12.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out12");
}
catch (e)
{
reportFailure("Testing TwelveOutIDispatch: " + e.toString());
}
try
{
obj.CreateError();
reportFailure("Testing CreateError: Didn't generate a catchable exception");
}
catch (e)
{
reportCompare(true, e.toString().search("CreateError Test") != -1, "Testing CreateError");
}
}

View File

@@ -1,361 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Rob Ginda rginda@netscape.com
*/
FAILED = "FAILED!: ";
STATUS = "STATUS: ";
BUGNUMBER = "BUGNUMBER: ";
DEBUGLINE = "DEBUG: ";
DEBUG = false;
VERBOSE = false;
var CLSID_nsXPCDispSimple = "{9F39237C-D179-4260-8EF3-4B6D4D7D5570}";
var ProgID_nsXPCDispSimple = "XPCIDispatchTest.nsXPCDispSimple.1";
var nsXPCDispSimpleDesc =
{
name : "nsXPCDispSimple",
cid : CLSID_nsXPCDispSimple,
progid : ProgID_nsXPCDispSimple,
scriptable : true,
methods :
[
"ClassName",
"Number"
]
};
var CLSID_nsXPCDispTestMethods = "{745D1149-9F46-418C-B176-71EAA98974BA}";
var ProgID_nsXPCDispTestMethods = "XPCIDispatchTest.nsXPCDispTestMethods.1";
var nsXPCDispTestMethodsDesc =
{
name : "nsXPCDispTestMethods",
cid : CLSID_nsXPCDispTestMethods,
progid : ProgID_nsXPCDispTestMethods,
scriptable : true,
methods :
[
"NoParameters", "ReturnBSTR", "ReturnI4",
"ReturnUI1", "ReturnI2", "ReturnR4", "ReturnR8", "ReturnBool",
"ReturnIDispatch", "ReturnError", "ReturnDate",
"ReturnIUnknown", "ReturnI1", "ReturnUI2", "ReturnUI4",
"ReturnInt", "ReturnUInt", "TakesBSTR", "TakesI4", "TakesUI1",
"TakesI2", "TakesR4", "TakesR8", "TakesBool",
"TakesIDispatch", "TakesError", "TakesDate", "TakesIUnknown",
"TakesI1", "TakesUI2", "TakesUI4", "TakesInt", "TakesUInt",
"OutputsBSTR", "OutputsI4", "OutputsUI1", "OutputsI2",
"OutputsR4", "OutputsR8", "OutputsBool", "OutputsIDispatch",
"OutputsError", "OutputsDate", "OutputsIUnknown", "OutputsI1",
"OutputsUI2", "OutputsUI4", "InOutsBSTR", "InOutsI4",
"InOutsUI1", "InOutsI2", "InOutsR4", "InOutsR8", "InOutsBool",
"InOutsIDispatch", "InOutsError", "InOutsDate",
"InOutsIUnknown", "InOutsI1", "InOutsUI2", "InOutsUI4",
"InOutsInt", "InOutsUInt", "OneParameterWithReturn",
"StringInputAndReturn", "IDispatchInputAndReturn",
"TwoParameters", "TwelveInParameters", "TwelveOutParameters",
"TwelveStrings", "TwelveOutStrings", "TwelveIDispatch",
"TwelveOutIDispatch", "CreateError"
]
};
var CLSID_nsXPCDispTestArrays = "{AB085C43-C619-48C8-B68C-C495BDE12DFB}";
var ProgID_nsXPCDispTestArrays = "XPCIDispatchTest.nsXPCDispTestArrays.1";
var nsXPCDispTestArraysDesc =
{
name : "nsXPCDispTestArrays",
cid : CLSID_nsXPCDispTestArrays,
progid : ProgID_nsXPCDispTestArrays,
scriptable : true,
methods :
[
"ReturnSafeArray", "ReturnSafeArrayBSTR", "ReturnSafeArrayIDispatch",
"TakesSafeArray", "TakesSafeArrayBSTR", "TakesSafeArrayIDispatch",
"InOutSafeArray", "InOutSafeArrayBSTR", "InOutSafeArrayIDispatch"
]
};
var CLSID_nsXPCDispTestNoIDispatch = "{7414404F-A4CC-4E3C-9B32-BB20CB22F541}";
var ProgID_nsXPCDispTestNoIDispatch = "XPCIDispatchTest.nsXPCDispTestNoIDispatch.1";
var CLSID_nsXPCDispTestNoScript = "{F8D54F00-4FC4-4731-B467-10F1CB8DB0AD}";
var ProgID_nsXPCDispTestNoScript = "XPCIDispatchTest.nsXPCDispTestNoScript.1";
var CLSID_nsXPCDispTestProperties = "{D8B4265B-1768-4CA9-A285-7CCAEEB51C74}";
var ProgID_nsXPCDispTestProperties = "XPCIDispatchTest.nsXPCDispTestProperties.1";
var nsXPCDispTestPropertiesDesc =
{
name : "nsXPCDispTestProperties",
cid : CLSID_nsXPCDispTestProperties,
progid : ProgID_nsXPCDispTestProperties,
scriptable : true,
methods :
[
"Short", "Long", "Float", "Double", "Currency",
"Date", "String", "DispatchPtr", "SCode", "Boolean", "Variant",
"COMPtr", "Char"
]
};
var CLSID_nsXPCDispTestScriptOn = "{2A06373F-3E61-4882-A3D7-A104F70B09ED}";
var ProgID_nsXPCDispTestScriptOn = "XPCIDispatchTest.nsXPCDispTestScriptOn.1";
var nsXPCDispTestScriptOnDesc =
{
name : "nsXPCDispTestScriptOn",
cid : CLSID_nsXPCDispTestScriptOn,
progid : ProgID_nsXPCDispTestScriptOn,
scriptable : true,
methods : [ ]
};
var CLSID_nsXPCDispTestScriptOff = "{959CD122-9826-4757-BA09-DE327D55F9E7}";
var ProgID_nsXPCDispTestScriptOff = "XPCIDispatchTest.nsXPCDispTestScriptOff.1";
var nsXPCDispTestScriptOffDesc =
{
name : "nsXPCDispTestScriptOff",
cid : CLSID_nsXPCDispTestScriptOff,
progid : ProgID_nsXPCDispTestScriptOff,
scriptable : false,
methods : [ ]
};
var CLSID_nsXPCDispTestWrappedJS = "{EAEE6BB2-C005-4B91-BCA7-6613236F6F69}";
var ProgID_nsXPCDispTestWrappedJS = "XPCIDispatchTest.nsXPCDispTestWrappedJS.1";
var nsXPCDispTestWrappedJSDesc =
{
name : "nsXPCDispTestWrappedJS",
cid : CLSID_nsXPCDispTestWrappedJS,
progid : ProgID_nsXPCDispTestWrappedJS,
scriptable : true,
methods :
[
"TestParamTypes"
]
};
// create list of COM components
var objectsDesc =
[
nsXPCDispSimpleDesc,
nsXPCDispTestMethodsDesc,
nsXPCDispTestArraysDesc,
nsXPCDispTestPropertiesDesc,
nsXPCDispTestScriptOnDesc,
nsXPCDispTestScriptOffDesc,
nsXPCDispTestWrappedJSDesc
];
function findProp(prop, array, marked)
{
len = array.length;
for (index = 0; index < len; ++index)
{
if (prop == array[index])
{
marked[index] = true;
return true;
}
}
return false;
}
function compareObject(obj, objDesc, testName)
{
if (obj == undefined)
{
reportFailure("compareObject passed an invalid object");
return;
}
var marked = new Array();
for (prop in obj)
{
printDebug("Found " + prop);
reportCompare(
true,
findProp(prop, objDesc.methods, marked),
testName + ": " + prop + " exists on " + objDesc.name + ", but was not expected");
}
len = objDesc.methods.length;
for (var index = 0; index < len; ++index)
{
reportCompare(
true,
marked[index],
testName + ": " + objDesc.methods[index] + " does not exist on " + objDesc.name);
}
}
function compareExpression(expression, expectedResult, testName)
{
if (VERBOSE && (typeof testName != "undefined"))
printStatus(testName + " - evaluating:" + expression);
try
{
reportCompare(
expectedResult,
eval(expression),
testName);
}
catch (e)
{
reportFailure(expression + " generated the following exception:" + e.toString());
}
}
var callStack = new Array();
/*
* Report a failure in the 'accepted' manner
*/
function reportFailure (msg)
{
var lines = msg.split ("\n");
var l;
var funcName = currentFunc();
var prefix = (funcName) ? "[reported from " + funcName + "] ": "";
for (var i=0; i<lines.length; i++)
print (FAILED + prefix + lines[i]);
}
/*
* Print a non-failure message.
*/
function printDebug (msg)
{
if (DEBUG)
{
var lines = msg.split ("\n");
var l;
for (var i=0; i<lines.length; i++)
print (DEBUGLINE + lines[i]);
}
}
/*
* Print a non-failure message.
*/
function printStatus (msg)
{
var lines = msg.split ("\n");
var l;
for (var i=0; i<lines.length; i++)
print (STATUS + lines[i]);
}
/*
* Print a bugnumber message.
*/
function printBugNumber (num)
{
print (BUGNUMBER + num);
}
/*
* Compare expected result to actual result, if they differ (in value and/or
* type) report a failure. If description is provided, include it in the
* failure report.
*/
function reportCompare (expected, actual, description)
{
var expected_t = typeof expected;
var actual_t = typeof actual;
var output = "";
if ((VERBOSE) && (typeof description != "undefined"))
printStatus ("Comparing '" + description + "'");
if (expected_t != actual_t)
output += "Type mismatch, expected type " + expected_t +
", actual type " + actual_t + "\n";
else if (VERBOSE)
printStatus ("Expected type '" + actual_t + "' matched actual " +
"type '" + expected_t + "'");
if (expected != actual)
output += "Expected value '" + expected + "', Actual value '" + actual +
"'\n";
else if (VERBOSE)
printStatus ("Expected value '" + actual + "' matched actual " +
"value '" + expected + "'");
if (output != "")
{
if (typeof description != "undefined")
reportFailure (description);
reportFailure (output);
}
}
/*
* Puts funcName at the top of the call stack. This stack is used to show
* a function-reported-from field when reporting failures.
*/
function enterFunc (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
callStack.push(funcName);
}
/*
* Pops the top funcName off the call stack. funcName is optional, and can be
* used to check push-pop balance.
*/
function exitFunc (funcName)
{
var lastFunc = callStack.pop();
if (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
if (lastFunc != funcName)
reportFailure ("Test driver failure, expected to exit function '" +
funcName + "' but '" + lastFunc + "' came off " +
"the stack");
}
}
/*
* Peeks at the top of the call stack.
*/
function currentFunc()
{
return callStack[callStack.length - 1];
}

View File

@@ -1,76 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the IDispatch implementation for XPConnect
*
* The Initial Developer of the Original Code is
* David Bradley.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* \file
* This file contains the tests for making sure that JS Objects access via the IDispatch interface
* work properly
*/
test();
function test()
{
try
{
var variantObj = Components.classes["@mozilla.org/variant;1"].createInstance(Components.interfaces.nsIVariant);
var jsobj =
{
Boolean : false,
Short : 0,
Long : 0,
Float : 0.0,
Double : 0.0,
Currency : 0.0,
Date : new Date(),
String : "",
DispatchPtr : {},
SCode : 0,
Variant : variantObj,
Char : 'a'
};
var obj = COMObject(CLSID_nsXPCDispTestWrappedJS);
reportCompare(
obj.TestParamTypes(jsobj),
"",
"Testing IDispatch wrapped JS objects");
}
catch (e)
{
reportFailure(e.toString());
}
}

View File

@@ -1,361 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released March
* 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Rob Ginda rginda@netscape.com
*/
FAILED = "FAILED!: ";
STATUS = "STATUS: ";
BUGNUMBER = "BUGNUMBER: ";
DEBUGLINE = "DEBUG: ";
DEBUG = false;
VERBOSE = false;
var CLSID_nsXPCDispSimple = "{9F39237C-D179-4260-8EF3-4B6D4D7D5570}";
var ProgID_nsXPCDispSimple = "XPCIDispatchTest.nsXPCDispSimple.1";
var nsXPCDispSimpleDesc =
{
name : "nsXPCDispSimple",
cid : CLSID_nsXPCDispSimple,
progid : ProgID_nsXPCDispSimple,
scriptable : true,
methods :
[
"ClassName",
"Number"
]
};
var CLSID_nsXPCDispTestMethods = "{745D1149-9F46-418C-B176-71EAA98974BA}";
var ProgID_nsXPCDispTestMethods = "XPCIDispatchTest.nsXPCDispTestMethods.1";
var nsXPCDispTestMethodsDesc =
{
name : "nsXPCDispTestMethods",
cid : CLSID_nsXPCDispTestMethods,
progid : ProgID_nsXPCDispTestMethods,
scriptable : true,
methods :
[
"NoParameters", "ReturnBSTR", "ReturnI4",
"ReturnUI1", "ReturnI2", "ReturnR4", "ReturnR8", "ReturnBool",
"ReturnIDispatch", "ReturnError", "ReturnDate",
"ReturnIUnknown", "ReturnI1", "ReturnUI2", "ReturnUI4",
"ReturnInt", "ReturnUInt", "TakesBSTR", "TakesI4", "TakesUI1",
"TakesI2", "TakesR4", "TakesR8", "TakesBool",
"TakesIDispatch", "TakesError", "TakesDate", "TakesIUnknown",
"TakesI1", "TakesUI2", "TakesUI4", "TakesInt", "TakesUInt",
"OutputsBSTR", "OutputsI4", "OutputsUI1", "OutputsI2",
"OutputsR4", "OutputsR8", "OutputsBool", "OutputsIDispatch",
"OutputsError", "OutputsDate", "OutputsIUnknown", "OutputsI1",
"OutputsUI2", "OutputsUI4", "InOutsBSTR", "InOutsI4",
"InOutsUI1", "InOutsI2", "InOutsR4", "InOutsR8", "InOutsBool",
"InOutsIDispatch", "InOutsError", "InOutsDate",
"InOutsIUnknown", "InOutsI1", "InOutsUI2", "InOutsUI4",
"InOutsInt", "InOutsUInt", "OneParameterWithReturn",
"StringInputAndReturn", "IDispatchInputAndReturn",
"TwoParameters", "TwelveInParameters", "TwelveOutParameters",
"TwelveStrings", "TwelveOutStrings", "TwelveIDispatch",
"TwelveOutIDispatch", "CreateError"
]
};
var CLSID_nsXPCDispTestArrays = "{AB085C43-C619-48C8-B68C-C495BDE12DFB}";
var ProgID_nsXPCDispTestArrays = "XPCIDispatchTest.nsXPCDispTestArrays.1";
var nsXPCDispTestArraysDesc =
{
name : "nsXPCDispTestArrays",
cid : CLSID_nsXPCDispTestArrays,
progid : ProgID_nsXPCDispTestArrays,
scriptable : true,
methods :
[
"ReturnSafeArray", "ReturnSafeArrayBSTR", "ReturnSafeArrayIDispatch",
"TakesSafeArray", "TakesSafeArrayBSTR", "TakesSafeArrayIDispatch",
"InOutSafeArray", "InOutSafeArrayBSTR", "InOutSafeArrayIDispatch"
]
};
var CLSID_nsXPCDispTestNoIDispatch = "{7414404F-A4CC-4E3C-9B32-BB20CB22F541}";
var ProgID_nsXPCDispTestNoIDispatch = "XPCIDispatchTest.nsXPCDispTestNoIDispatch.1";
var CLSID_nsXPCDispTestNoScript = "{F8D54F00-4FC4-4731-B467-10F1CB8DB0AD}";
var ProgID_nsXPCDispTestNoScript = "XPCIDispatchTest.nsXPCDispTestNoScript.1";
var CLSID_nsXPCDispTestProperties = "{D8B4265B-1768-4CA9-A285-7CCAEEB51C74}";
var ProgID_nsXPCDispTestProperties = "XPCIDispatchTest.nsXPCDispTestProperties.1";
var nsXPCDispTestPropertiesDesc =
{
name : "nsXPCDispTestProperties",
cid : CLSID_nsXPCDispTestProperties,
progid : ProgID_nsXPCDispTestProperties,
scriptable : true,
methods :
[
"Short", "Long", "Float", "Double", "Currency",
"Date", "String", "DispatchPtr", "SCode", "Boolean", "Variant",
"COMPtr", "Char"
]
};
var CLSID_nsXPCDispTestScriptOn = "{2A06373F-3E61-4882-A3D7-A104F70B09ED}";
var ProgID_nsXPCDispTestScriptOn = "XPCIDispatchTest.nsXPCDispTestScriptOn.1";
var nsXPCDispTestScriptOnDesc =
{
name : "nsXPCDispTestScriptOn",
cid : CLSID_nsXPCDispTestScriptOn,
progid : ProgID_nsXPCDispTestScriptOn,
scriptable : true,
methods : [ ]
};
var CLSID_nsXPCDispTestScriptOff = "{959CD122-9826-4757-BA09-DE327D55F9E7}";
var ProgID_nsXPCDispTestScriptOff = "XPCIDispatchTest.nsXPCDispTestScriptOff.1";
var nsXPCDispTestScriptOffDesc =
{
name : "nsXPCDispTestScriptOff",
cid : CLSID_nsXPCDispTestScriptOff,
progid : ProgID_nsXPCDispTestScriptOff,
scriptable : false,
methods : [ ]
};
var CLSID_nsXPCDispTestWrappedJS = "{EAEE6BB2-C005-4B91-BCA7-6613236F6F69}";
var ProgID_nsXPCDispTestWrappedJS = "XPCIDispatchTest.nsXPCDispTestWrappedJS.1";
var nsXPCDispTestWrappedJSDesc =
{
name : "nsXPCDispTestWrappedJS",
cid : CLSID_nsXPCDispTestWrappedJS,
progid : ProgID_nsXPCDispTestWrappedJS,
scriptable : true,
methods :
[
"TestParamTypes"
]
};
// create list of COM components
var objectsDesc =
[
nsXPCDispSimpleDesc,
nsXPCDispTestMethodsDesc,
nsXPCDispTestArraysDesc,
nsXPCDispTestPropertiesDesc,
nsXPCDispTestScriptOnDesc,
nsXPCDispTestScriptOffDesc,
nsXPCDispTestWrappedJSDesc
];
function findProp(prop, array, marked)
{
len = array.length;
for (index = 0; index < len; ++index)
{
if (prop == array[index])
{
marked[index] = true;
return true;
}
}
return false;
}
function compareObject(obj, objDesc, testName)
{
if (obj == undefined)
{
reportFailure("compareObject passed an invalid object");
return;
}
var marked = new Array();
for (prop in obj)
{
printDebug("Found " + prop);
reportCompare(
true,
findProp(prop, objDesc.methods, marked),
testName + ": " + prop + " exists on " + objDesc.name + ", but was not expected");
}
len = objDesc.methods.length;
for (var index = 0; index < len; ++index)
{
reportCompare(
true,
marked[index],
testName + ": " + objDesc.methods[index] + " does not exist on " + objDesc.name);
}
}
function compareExpression(expression, expectedResult, testName)
{
if (VERBOSE && (typeof testName != "undefined"))
printStatus(testName + " - evaluating:" + expression);
try
{
reportCompare(
expectedResult,
eval(expression),
testName);
}
catch (e)
{
reportFailure(expression + " generated the following exception:" + e.toString());
}
}
var callStack = new Array();
/*
* Report a failure in the 'accepted' manner
*/
function reportFailure (msg)
{
var lines = msg.split ("\n");
var l;
var funcName = currentFunc();
var prefix = (funcName) ? "[reported from " + funcName + "] ": "";
for (var i=0; i<lines.length; i++)
print (FAILED + prefix + lines[i]);
}
/*
* Print a non-failure message.
*/
function printDebug (msg)
{
if (DEBUG)
{
var lines = msg.split ("\n");
var l;
for (var i=0; i<lines.length; i++)
print (DEBUGLINE + lines[i]);
}
}
/*
* Print a non-failure message.
*/
function printStatus (msg)
{
var lines = msg.split ("\n");
var l;
for (var i=0; i<lines.length; i++)
print (STATUS + lines[i]);
}
/*
* Print a bugnumber message.
*/
function printBugNumber (num)
{
print (BUGNUMBER + num);
}
/*
* Compare expected result to actual result, if they differ (in value and/or
* type) report a failure. If description is provided, include it in the
* failure report.
*/
function reportCompare (expected, actual, description)
{
var expected_t = typeof expected;
var actual_t = typeof actual;
var output = "";
if ((VERBOSE) && (typeof description != "undefined"))
printStatus ("Comparing '" + description + "'");
if (expected_t != actual_t)
output += "Type mismatch, expected type " + expected_t +
", actual type " + actual_t + "\n";
else if (VERBOSE)
printStatus ("Expected type '" + actual_t + "' matched actual " +
"type '" + expected_t + "'");
if (expected != actual)
output += "Expected value '" + expected + "', Actual value '" + actual +
"'\n";
else if (VERBOSE)
printStatus ("Expected value '" + actual + "' matched actual " +
"value '" + expected + "'");
if (output != "")
{
if (typeof description != "undefined")
reportFailure (description);
reportFailure (output);
}
}
/*
* Puts funcName at the top of the call stack. This stack is used to show
* a function-reported-from field when reporting failures.
*/
function enterFunc (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
callStack.push(funcName);
}
/*
* Pops the top funcName off the call stack. funcName is optional, and can be
* used to check push-pop balance.
*/
function exitFunc (funcName)
{
var lastFunc = callStack.pop();
if (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
if (lastFunc != funcName)
reportFailure ("Test driver failure, expected to exit function '" +
funcName + "' but '" + lastFunc + "' came off " +
"the stack");
}
}
/*
* Peeks at the top of the call stack.
*/
function currentFunc()
{
return callStack[callStack.length - 1];
}

View File

@@ -1 +0,0 @@
perl jsDriver.pl -e xpcshell %1 %2 %3 %4 %5 %6 %7 %8 %9

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,33 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src decoders
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,32 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = ppm png gif jpeg
include $(topsrcdir)/config/rules.mk

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,323 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef _GIF_H_
#define _GIF_H_
/* gif2.h
The interface for the GIF87/89a decoder.
*/
// List of possible parsing states
typedef enum {
gif_gather,
gif_init, //1
gif_type,
gif_version,
gif_global_header,
gif_global_colormap,
gif_image_start, //6
gif_image_header,
gif_image_colormap,
gif_image_body,
gif_lzw_start,
gif_lzw, //11
gif_sub_block,
gif_extension,
gif_control_extension,
gif_consume_block,
gif_skip_block,
gif_done, //17
gif_oom,
gif_error,
gif_comment_extension,
gif_application_extension,
gif_netscape_extension_block,
gif_consume_netscape_extension,
gif_consume_comment,
gif_delay,
gif_wait_for_buffer_full,
gif_stop_animating //added for animation stop
} gstate;
/* "Disposal" method indicates how the image should be handled in the
framebuffer before the subsequent image is displayed. */
typedef enum
{
DISPOSE_NOT_SPECIFIED = 0,
DISPOSE_KEEP = 1, /* Leave it in the framebuffer */
DISPOSE_OVERWRITE_BGCOLOR = 2, /* Overwrite with background color */
DISPOSE_OVERWRITE_PREVIOUS = 4 /* Save-under */
} gdispose;
/* A RGB triplet representing a single pixel in the image's colormap
(if present.) */
typedef struct _GIF_RGB
{
PRUint8 red, green, blue, pad; /* Windows requires the fourth byte &
many compilers pad it anyway. */
/* XXX: hist_count appears to be unused */
//PRUint16 hist_count; /* Histogram frequency count. */
} GIF_RGB;
/* Colormap information. */
typedef struct _GIF_ColorMap {
int32 num_colors; /* Number of colors in the colormap.
A negative value can be used to denote a
possibly non-unique set. */
GIF_RGB *map; /* Colormap colors. */
PRUint8 *index; /* NULL, if map is in index order. Otherwise
specifies the indices of the map entries. */
void *table; /* Lookup table for this colormap. Private to
the Image Library. */
} GIF_ColorMap;
/* An indexed RGB triplet. */
typedef struct _GIF_IRGB {
PRUint8 index;
PRUint8 red, green, blue;
} GIF_IRGB;
/* A GIF decoder's state */
typedef struct gif_struct {
void* clientptr;
/* Callbacks for this decoder instance*/
int (PR_CALLBACK *GIFCallback_NewPixmap)();
int (PR_CALLBACK *GIFCallback_BeginGIF)(
void* aClientData,
PRUint32 aLogicalScreenWidth,
PRUint32 aLogicalScreenHeight,
PRUint8 aLogicalScreenBackgroundRGBIndex);
int (PR_CALLBACK* GIFCallback_EndGIF)(
void* aClientData,
int aAnimationLoopCount);
int (PR_CALLBACK* GIFCallback_BeginImageFrame)(
void* aClientData,
PRUint32 aFrameNumber, /* Frame number, 1-n */
PRUint32 aFrameXOffset, /* X offset in logical screen */
PRUint32 aFrameYOffset, /* Y offset in logical screen */
PRUint32 aFrameWidth,
PRUint32 aFrameHeight,
GIF_RGB* aTransparencyChromaKey);
int (PR_CALLBACK* GIFCallback_EndImageFrame)(
void* aClientData,
PRUint32 aFrameNumber,
PRUint32 aDelayTimeout);
int (PR_CALLBACK* GIFCallback_SetupColorspaceConverter)();
int (PR_CALLBACK* GIFCallback_ResetPalette)();
int (PR_CALLBACK* GIFCallback_InitTransparentPixel)();
int (PR_CALLBACK* GIFCallback_DestroyTransparentPixel)();
int (PR_CALLBACK* GIFCallback_HaveDecodedRow)(
void* aClientData,
PRUint8* aRowBufPtr, /* Pointer to single scanline temporary buffer */
PRUint8* aRGBrowBufPtr,/* Pointer to temporary storage for dithering/mapping */
int aXOffset, /* With respect to GIF logical screen origin */
int aLength, /* Length of the row? */
int aRow, /* Row number? */
int aDuplicateCount, /* Number of times to duplicate the row? */
PRUint8 aDrawMode, /* il_draw_mode */
int aInterlacePass);
int (PR_CALLBACK *GIFCallback_HaveImageAll)(
void* aClientData);
/* Parsing state machine */
gstate state; /* Curent decoder master state */
PRUint8 *hold; /* Accumulation buffer */
int32 hold_size; /* Capacity, in bytes, of accumulation buffer */
PRUint8 *gather_head; /* Next byte to read in accumulation buffer */
int32 gather_request_size; /* Number of bytes to accumulate */
int32 gathered; /* bytes accumulated so far*/
gstate post_gather_state; /* State after requested bytes accumulated */
int32 requested_buffer_fullness; /* For netscape application extension */
/* LZW decoder state machine */
PRUint8 *stack; /* Base of decoder stack */
PRUint8 *stackp; /* Current stack pointer */
PRUint16 *prefix;
PRUint8 *suffix;
int datasize;
int codesize;
int codemask;
int clear_code; /* Codeword used to trigger dictionary reset */
int avail; /* Index of next available slot in dictionary */
int oldcode;
PRUint8 firstchar;
int count; /* Remaining # bytes in sub-block */
int bits; /* Number of unread bits in "datum" */
int32 datum; /* 32-bit input buffer */
/* Output state machine */
int ipass; /* Interlace pass; Ranges 1-4 if interlaced. */
PRUintn rows_remaining; /* Rows remaining to be output */
PRUintn irow; /* Current output row, starting at zero */
PRUint8 *rgbrow; /* Temporary storage for dithering/mapping */
PRUint8 *rowbuf; /* Single scanline temporary buffer */
PRUint8 *rowend; /* Pointer to end of rowbuf */
PRUint8 *rowp; /* Current output pointer */
/* Parameters for image frame currently being decoded*/
PRUintn x_offset, y_offset; /* With respect to "screen" origin */
PRUintn height, width;
PRUintn last_x_offset, last_y_offset; /* With respect to "screen" origin */
PRUintn last_height, last_width;
int interlaced; /* TRUE, if scanlines arrive interlaced order */
int tpixel; /* Index of transparent pixel */
GIF_IRGB* transparent_pixel;
int is_transparent; /* TRUE, if tpixel is valid */
int control_extension; /* TRUE, if image control extension present */
int is_local_colormap_defined;
gdispose disposal_method; /* Restore to background, leave in place, etc.*/
gdispose last_disposal_method;
GIF_RGB *local_colormap; /* Per-image colormap */
int local_colormap_size; /* Size of local colormap array. */
PRUint32 delay_time; /* Display time, in milliseconds,
for this image in a multi-image GIF */
/* Global (multi-image) state */
int screen_bgcolor; /* Logical screen background color */
int version; /* Either 89 for GIF89 or 87 for GIF87 */
PRUintn screen_width; /* Logical screen width & height */
PRUintn screen_height;
GIF_RGB *global_colormap; /* Default colormap if local not supplied */
int global_colormap_size; /* Size of global colormap array. */
int images_decoded; /* Counts images for multi-part GIFs */
int destroy_pending; /* Stream has ended */
int progressive_display; /* If TRUE, do Haeberli interlace hack */
int loop_count; /* Netscape specific extension block to control
the number of animation loops a GIF renders. */
} gif_struct;
/* Create a new gif_struct */
extern PRBool gif_create(gif_struct **gs);
/* These are the APIs that the client calls to intialize,
push data to, and shut down the GIF decoder. */
PRBool GIFInit(
gif_struct* gs,
void* aClientData,
int (*PR_CALLBACK GIFCallback_NewPixmap)(),
int (*PR_CALLBACK GIFCallback_BeginGIF)(
void* aClientData,
PRUint32 aLogicalScreenWidth,
PRUint32 aLogicalScreenHeight,
PRUint8 aBackgroundRGBIndex),
int (*PR_CALLBACK GIFCallback_EndGIF)(
void* aClientData,
int aAnimationLoopCount),
int (*PR_CALLBACK GIFCallback_BeginImageFrame)(
void* aClientData,
PRUint32 aFrameNumber, /* Frame number, 1-n */
PRUint32 aFrameXOffset, /* X offset in logical screen */
PRUint32 aFrameYOffset, /* Y offset in logical screen */
PRUint32 aFrameWidth,
PRUint32 aFrameHeight,
GIF_RGB* aTransparencyChromaKey),
int (*PR_CALLBACK GIFCallback_EndImageFrame)(
void* aClientData,
PRUint32 aFrameNumber,
PRUint32 aDelayTimeout),
int (*PR_CALLBACK GIFCallback_SetupColorspaceConverter)(),
int (*PR_CALLBACK GIFCallback_ResetPalette)(),
int (*PR_CALLBACK GIFCallback_InitTransparentPixel)(),
int (*PR_CALLBACK GIFCallback_DestroyTransparentPixel)(),
int (*PR_CALLBACK GIFCallback_HaveDecodedRow)(
void* aClientData,
PRUint8* aRowBufPtr, /* Pointer to single scanline temporary buffer */
PRUint8* aRGBrowBufPtr,/* Pointer to temporary storage for dithering/mapping */
int aXOffset, /* With respect to GIF logical screen origin */
int aLength, /* Length of the row? */
int aRow, /* Row number? */
int aDuplicateCount, /* Number of times to duplicate the row? */
PRUint8 aDrawMode, /* il_draw_mode */
int aInterlacePass),
int (*PR_CALLBACK GIFCallback_HaveImageAll)(
void* aClientData)
);
extern void gif_destroy(gif_struct* aGIFStruct);
int gif_write(gif_struct* aGIFStruct, const PRUint8 * buf, PRUint32 numbytes);
PRUint8 gif_write_ready(gif_struct* aGIFStruct);
extern void gif_complete(gif_struct** aGIFStruct);
extern void gif_delay_time_callback(/* void *closure */);
/* Callback functions that the client must implement and pass in
pointers for during the GIFInit call. These will be called back
when the decoder has a decoded rows, frame size information, etc.*/
/* GIFCallback_LogicalScreenSize is called only once to notify the client
of the logical screen size, which will be the size of the total image. */
typedef int (*PR_CALLBACK BEGINGIF_CALLBACK)(
void* aClientData,
PRUint32 aLogicalScreenWidth,
PRUint32 aLogicalScreenHeight,
PRUint8 aLogicalScreenBackgroundRGBIndex);
typedef int (PR_CALLBACK *GIFCallback_EndGIF)(
void* aClientData,
int aAnimationLoopCount);
/* GIFCallback_BeginImageFrame is called at the beginning of each frame of
a GIF.*/
typedef int (PR_CALLBACK *GIFCallback_BeginImageFrame)(
void* aClientData,
PRUint32 aFrameNumber, /* Frame number, 1-n */
PRUint32 aFrameXOffset, /* X offset in logical screen */
PRUint32 aFraqeYOffset, /* Y offset in logical screen */
PRUint32 aFrameWidth,
PRUint32 aFrameHeight);
extern int GIFCallback_EndImageFrame(
void* aClientData,
PRUint32 aFrameNumber,
PRUint32 aDelayTimeout); /* Time in milliseconds this frame should be displayed before the next frame.
This information appears in a sub control block, so we don't
transmit it back to the client until we're done with the frame. */
/*
extern int GIFCallback_SetupColorspaceConverter();
extern int GIFCallback_ResetPalette();
extern int GIFCallback_InitTransparentPixel();
extern int GIFCallback_DestroyTransparentPixel();
*/
extern int GIFCallback_HaveDecodedRow();
extern int GIFCallback_HaveImageAll();
#endif

View File

@@ -0,0 +1,42 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = imggif
LIBRARY_NAME = imggif
IS_COMPONENT = 1
REQUIRES = xpcom necko layout gfx2 imglib2
CPPSRCS = GIF2.cpp nsGIFDecoder2.cpp nsGIFModule.cpp
EXTRA_DSO_LDOPTS = $(GIF_LIBS) $(ZLIB_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,52 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Stuart Parmenter <pavlov@netscape.com>
#
DEPTH=..\..\..\..
include <$(DEPTH)/config/config.mak>
MODULE = imggif
LIBRARY_NAME = imggif
DLL = $(OBJDIR)\$(LIBRARY_NAME).dll
MAKE_OBJ_TYPE = DLL
OBJS = \
.\$(OBJDIR)\nsGIFDecoder2.obj \
.\$(OBJDIR)\GIF2.obj \
.\$(OBJDIR)\nsGIFModule.obj \
$(NULL)
LLIBS=\
$(LIBNSPR) \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\gkgfxwin.lib \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(LIBRARY_NAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(LIBRARY_NAME).lib $(DIST)\lib
clobber::
rm -f $(DIST)\bin\components\$(LIBRARY_NAME).dll
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,506 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Chris Saari <saari@netscape.com>
*/
#include "nsGIFDecoder2.h"
#include "nsIInputStream.h"
#include "nsIComponentManager.h"
#include "nsIImage.h"
#include "nsMemory.h"
#include "imgIContainerObserver.h"
#include "nsRect.h"
//////////////////////////////////////////////////////////////////////
// GIF Decoder Implementation
// This is an adaptor between GIF2 and imgIDecoder
NS_IMPL_ISUPPORTS2(nsGIFDecoder2, imgIDecoder, nsIOutputStream);
nsGIFDecoder2::nsGIFDecoder2()
{
NS_INIT_ISUPPORTS();
mImageFrame = nsnull;
mGIFStruct = nsnull;
mAlphaLine = nsnull;
}
nsGIFDecoder2::~nsGIFDecoder2(void)
{
if (mAlphaLine)
nsMemory::Free(mAlphaLine);
if (mGIFStruct) {
gif_destroy(mGIFStruct);
mGIFStruct = nsnull;
}
}
//******************************************************************************
/** imgIDecoder methods **/
//******************************************************************************
//******************************************************************************
/* void init (in imgIRequest aRequest); */
NS_IMETHODIMP nsGIFDecoder2::Init(imgIRequest *aRequest)
{
mImageRequest = aRequest;
mObserver = do_QueryInterface(aRequest); // we're holding 2 strong refs to the request.
aRequest->GetImage(getter_AddRefs(mImageContainer));
/* do gif init stuff */
/* Always decode to 24 bit pixdepth */
PRBool created = gif_create(&mGIFStruct);
NS_ASSERTION(created, "gif_create failed");
// Call GIF decoder init routine
GIFInit(
mGIFStruct,
this,
NewPixmap,
BeginGIF,
EndGIF,
BeginImageFrame,
EndImageFrame,
SetupColorspaceConverter,
ResetPalette,
InitTransparentPixel,
DestroyTransparentPixel,
HaveDecodedRow,
HaveImageAll);
return NS_OK;
}
//******************************************************************************
/* readonly attribute imgIRequest request; */
NS_IMETHODIMP nsGIFDecoder2::GetRequest(imgIRequest * *aRequest)
{
*aRequest = mImageRequest;
NS_IF_ADDREF(*aRequest);
return NS_OK;
}
//******************************************************************************
/** nsIOutputStream methods **/
//******************************************************************************
//******************************************************************************
/* void close (); */
NS_IMETHODIMP nsGIFDecoder2::Close()
{
if (mGIFStruct) {
gif_destroy(mGIFStruct);
mGIFStruct = nsnull;
}
return NS_OK;
}
//******************************************************************************
/* void flush (); */
NS_IMETHODIMP nsGIFDecoder2::Flush()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//******************************************************************************
/* unsigned long write (in string buf, in unsigned long count); */
NS_IMETHODIMP nsGIFDecoder2::Write(const char *buf, PRUint32 count, PRUint32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//******************************************************************************
/* static callback from nsIInputStream::ReadSegments */
static NS_METHOD ReadDataOut(nsIInputStream* in,
void* closure,
const char* fromRawSegment,
PRUint32 toOffset,
PRUint32 count,
PRUint32 *writeCount)
{
nsGIFDecoder2 *decoder = NS_STATIC_CAST(nsGIFDecoder2*, closure);
*writeCount = decoder->ProcessData((unsigned char*)fromRawSegment, count);
return NS_OK;
}
//******************************************************************************
PRUint32 nsGIFDecoder2::ProcessData(unsigned char *data, PRUint32 count)
{
// Push the data to the GIF decoder
// First we ask if the gif decoder is ready for more data, and if so, push it.
// In the new decoder, we should always be able to process more data since
// we don't wait to decode each frame in an animation now.
if(gif_write_ready(mGIFStruct)) {
gif_write(mGIFStruct, data, count);
}
return count; // we always consume all the data
}
//******************************************************************************
/* unsigned long writeFrom (in nsIInputStream inStr, in unsigned long count); */
NS_IMETHODIMP nsGIFDecoder2::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval)
{
inStr->ReadSegments(
ReadDataOut, // Callback
this,
count,
_retval);
// if error
//mRequest->Cancel(NS_BINDING_ABORTED); // XXX is this the correct error ?
return NS_OK;
}
//******************************************************************************
/* [noscript] unsigned long writeSegments (in nsReadSegmentFun reader, in voidPtr closure, in unsigned long count); */
NS_IMETHODIMP nsGIFDecoder2::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//******************************************************************************
/* attribute boolean nonBlocking; */
NS_IMETHODIMP nsGIFDecoder2::GetNonBlocking(PRBool *aNonBlocking)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//******************************************************************************
NS_IMETHODIMP nsGIFDecoder2::SetNonBlocking(PRBool aNonBlocking)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//******************************************************************************
/* attribute nsIOutputStreamObserver observer; */
NS_IMETHODIMP nsGIFDecoder2::GetObserver(nsIOutputStreamObserver * *aObserver)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//******************************************************************************
NS_IMETHODIMP nsGIFDecoder2::SetObserver(nsIOutputStreamObserver * aObserver)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//******************************************************************************
// GIF decoder callback methods. Part of pulic API for GIF2
//******************************************************************************
//******************************************************************************
int BeginGIF(
void* aClientData,
PRUint32 aLogicalScreenWidth,
PRUint32 aLogicalScreenHeight,
PRUint8 aBackgroundRGBIndex)
{
// copy GIF info into imagelib structs
nsGIFDecoder2 *decoder = NS_STATIC_CAST(nsGIFDecoder2*, aClientData);
if (decoder->mObserver)
decoder->mObserver->OnStartDecode(nsnull, nsnull);
decoder->mImageContainer->Init(aLogicalScreenWidth, aLogicalScreenHeight, decoder->mObserver);
if (decoder->mObserver)
decoder->mObserver->OnStartContainer(nsnull, nsnull, decoder->mImageContainer);
return 0;
}
//******************************************************************************
int EndGIF(
void* aClientData,
int aAnimationLoopCount)
{
nsGIFDecoder2 *decoder = NS_STATIC_CAST(nsGIFDecoder2*, aClientData);
if (decoder->mObserver) {
decoder->mObserver->OnStopContainer(nsnull, nsnull, decoder->mImageContainer);
decoder->mObserver->OnStopDecode(nsnull, nsnull, NS_OK, nsnull);
}
decoder->mImageContainer->SetLoopCount(aAnimationLoopCount);
decoder->mImageContainer->DecodingComplete();
return 0;
}
//******************************************************************************
int BeginImageFrame(
void* aClientData,
PRUint32 aFrameNumber, /* Frame number, 1-n */
PRUint32 aFrameXOffset, /* X offset in logical screen */
PRUint32 aFrameYOffset, /* Y offset in logical screen */
PRUint32 aFrameWidth,
PRUint32 aFrameHeight,
GIF_RGB* aTransparencyChromaKey) /* don't have this info yet */
{
nsGIFDecoder2* decoder = NS_STATIC_CAST(nsGIFDecoder2*, aClientData);
decoder->mImageFrame = nsnull; // clear out our current frame reference
decoder->mGIFStruct->x_offset = aFrameXOffset;
decoder->mGIFStruct->y_offset = aFrameYOffset;
decoder->mGIFStruct->width = aFrameWidth;
decoder->mGIFStruct->height = aFrameHeight;
return 0;
}
//******************************************************************************
int EndImageFrame(
void* aClientData,
PRUint32 aFrameNumber,
PRUint32 aDelayTimeout) /* Time this frame should be displayed before the next frame
we can't have this in the image frame init because it doesn't
show up in the GIF frame header, it shows up in a sub control
block.*/
{
nsGIFDecoder2* decoder = NS_STATIC_CAST(nsGIFDecoder2*, aClientData);
// We actually have the timeout information before we get the lzw encoded image
// data, at least according to the spec, but we delay in setting the timeout for
// the image until here to help ensure that we have the whole image frame decoded before
// we go off and try to display another frame.
// XXXXXXXX
// decoder->mImageFrame->SetTimeout(aDelayTimeout);
decoder->mImageContainer->EndFrameDecode(aFrameNumber, aDelayTimeout);
if (decoder->mObserver)
decoder->mObserver->OnStopFrame(nsnull, nsnull, decoder->mImageFrame);
decoder->mImageFrame = nsnull;
return 0;
}
//******************************************************************************
// GIF decoder callback
int HaveImageAll(
void* aClientData)
{
return 0;
}
//******************************************************************************
// GIF decoder callback notification that it has decoded a row
int HaveDecodedRow(
void* aClientData,
PRUint8* aRowBufPtr, // Pointer to single scanline temporary buffer
PRUint8* aRGBrowBufPtr,// Pointer to temporary storage for dithering/mapping
int aXOffset, // With respect to GIF logical screen origin
int aLength, // Length of the row?
int aRowNumber, // Row number?
int aDuplicateCount, // Number of times to duplicate the row?
PRUint8 aDrawMode, // il_draw_mode
int aInterlacePass) // interlace pass (1-4)
{
nsGIFDecoder2* decoder = NS_STATIC_CAST(nsGIFDecoder2*, aClientData);
PRUint32 bpr, abpr;
// We have to delay allocation of the image frame until now because
// we won't have control block info (transparency) until now. The conrol
// block of a GIF stream shows up after the image header since transparency
// is added in GIF89a and control blocks are how the extensions are done.
// How annoying.
if(! decoder->mImageFrame) {
gfx_format format = gfxIFormats::RGB;
if (decoder->mGIFStruct->is_transparent)
format = gfxIFormats::RGB_A1;
#ifdef XP_PC
// XXX this works...
format += 1; // RGB to BGR
#endif
// initalize the frame and append it to the container
decoder->mImageFrame = do_CreateInstance("@mozilla.org/gfx/image/frame;2");
decoder->mImageFrame->Init(
decoder->mGIFStruct->x_offset, decoder->mGIFStruct->y_offset,
decoder->mGIFStruct->width, decoder->mGIFStruct->height, format);
decoder->mImageContainer->AppendFrame(decoder->mImageFrame);
if (decoder->mObserver)
decoder->mObserver->OnStartFrame(nsnull, nsnull, decoder->mImageFrame);
decoder->mImageFrame->GetImageBytesPerRow(&bpr);
decoder->mImageFrame->GetAlphaBytesPerRow(&abpr);
if (format == gfxIFormats::RGB_A1 || format == gfxIFormats::BGR_A1) {
if (decoder->mAlphaLine)
nsMemory::Free(decoder->mAlphaLine);
decoder->mAlphaLine = (PRUint8 *)nsMemory::Alloc(abpr);
}
} else {
decoder->mImageFrame->GetImageBytesPerRow(&bpr);
decoder->mImageFrame->GetAlphaBytesPerRow(&abpr);
}
if (aRowBufPtr) {
nscoord width;
decoder->mImageFrame->GetWidth(&width);
PRUint32 iwidth = width;
gfx_format format;
decoder->mImageFrame->GetFormat(&format);
// XXX map the data into colors
int cmapsize;
GIF_RGB* cmap;
if(decoder->mGIFStruct->local_colormap) {
cmapsize = decoder->mGIFStruct->local_colormap_size;
cmap = decoder->mGIFStruct->local_colormap;
} else {
cmapsize = decoder->mGIFStruct->global_colormap_size;
cmap = decoder->mGIFStruct->global_colormap;
}
PRUint8* rgbRowIndex = aRGBrowBufPtr;
PRUint8* rowBufIndex = aRowBufPtr;
switch (format) {
case gfxIFormats::RGB:
{
while(rowBufIndex != decoder->mGIFStruct->rowend) {
#ifdef XP_MAC
*rgbRowIndex++ = 0; // Mac is always 32bits per pixel, this is pad
#endif
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].red;
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].green;
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].blue;
++rowBufIndex;
}
decoder->mImageFrame->SetImageData((PRUint8*)aRGBrowBufPtr, bpr, aRowNumber*bpr);
}
break;
case gfxIFormats::BGR:
{
while(rowBufIndex != decoder->mGIFStruct->rowend) {
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].blue;
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].green;
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].red;
++rowBufIndex;
}
decoder->mImageFrame->SetImageData((PRUint8*)aRGBrowBufPtr, bpr, aRowNumber*bpr);
}
break;
case gfxIFormats::RGB_A1:
case gfxIFormats::BGR_A1:
{
memset(aRGBrowBufPtr, 0, bpr);
memset(decoder->mAlphaLine, 0, abpr);
PRUint32 iwidth = (PRUint32)width;
for (PRUint32 x=0; x<iwidth; x++) {
if (*rowBufIndex != decoder->mGIFStruct->tpixel) {
#ifdef XP_PC
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].blue;
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].green;
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].red;
#else
#ifdef XP_MAC
*rgbRowIndex++ = 0; // Mac is always 32bits per pixel, this is pad
#endif
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].red;
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].green;
*rgbRowIndex++ = cmap[PRUint8(*rowBufIndex)].blue;
#endif
decoder->mAlphaLine[x>>3] |= 1<<(7-x&0x7);
} else {
#ifdef XP_MAC
rgbRowIndex+=4;
#else
rgbRowIndex+=3;
#endif
}
++rowBufIndex;
}
decoder->mImageFrame->SetImageData((PRUint8*)aRGBrowBufPtr, bpr, aRowNumber*bpr);
decoder->mImageFrame->SetAlphaData(decoder->mAlphaLine, abpr, aRowNumber*abpr);
}
break;
default:
break;
}
nsRect r(0, aRowNumber, width, 1);
decoder->mObserver->OnDataAvailable(nsnull, nsnull, decoder->mImageFrame, &r);
}
return 0;
}
//******************************************************************************
int ResetPalette()
{
return 0;
}
//******************************************************************************
int SetupColorspaceConverter()
{
return 0;
}
//******************************************************************************
int EndImageFrame()
{
return 0;
}
//******************************************************************************
int NewPixmap()
{
return 0;
}
//******************************************************************************
int InitTransparentPixel()
{
return 0;
}
//******************************************************************************
int DestroyTransparentPixel()
{
return 0;
}

View File

@@ -0,0 +1,114 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Chris Saari <saari@netscape.com>
*/
#ifndef _nsGIFDecoder2_h
#define _nsGIFDecoder2_h
#include "nsCOMPtr.h"
#include "imgIDecoder.h"
#include "imgIContainer.h"
#include "imgIDecoderObserver.h"
#include "gfxIImageFrame.h"
#include "imgIRequest.h"
#include "GIF2.h"
#define NS_GIFDECODER2_CID \
{ /* 797bec5a-1dd2-11b2-a7f8-ca397e0179c4 */ \
0x797bec5a, \
0x1dd2, \
0x11b2, \
{0xa7, 0xf8, 0xca, 0x39, 0x7e, 0x01, 0x79, 0xc4} \
}
//////////////////////////////////////////////////////////////////////
// nsGIFDecoder2 Definition
class nsGIFDecoder2 : public imgIDecoder
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMGIDECODER
NS_DECL_NSIOUTPUTSTREAM
nsGIFDecoder2();
virtual ~nsGIFDecoder2();
static NS_METHOD Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
NS_METHOD ProcessData(unsigned char *data, PRUint32 count);
nsCOMPtr<imgIContainer> mImageContainer;
nsCOMPtr<gfxIImageFrame> mImageFrame;
nsCOMPtr<imgIRequest> mImageRequest;
nsCOMPtr<imgIDecoderObserver> mObserver; // this is just qi'd from mRequest for speed
gif_struct *mGIFStruct;
PRUint8 *mAlphaLine;
};
// static callbacks for the GIF decoder
static int PR_CALLBACK BeginGIF(
void* aClientData,
PRUint32 aLogicalScreenWidth,
PRUint32 aLogicalScreenHeight,
PRUint8 aBackgroundRGBIndex);
static int PR_CALLBACK HaveDecodedRow(
void* aClientData,
PRUint8* aRowBufPtr, // Pointer to single scanline temporary buffer
PRUint8* aRGBrowBufPtr,// Pointer to temporary storage for dithering/mapping
int aXOffset, // With respect to GIF logical screen origin
int aLength, // Length of the row?
int aRow, // Row number?
int aDuplicateCount, // Number of times to duplicate the row?
PRUint8 aDrawMode, // il_draw_mode
int aInterlacePass);
static int PR_CALLBACK NewPixmap();
static int PR_CALLBACK EndGIF(
void* aClientData,
int aAnimationLoopCount);
static int PR_CALLBACK BeginImageFrame(
void* aClientData,
PRUint32 aFrameNumber, /* Frame number, 1-n */
PRUint32 aFrameXOffset, /* X offset in logical screen */
PRUint32 aFrameYOffset, /* Y offset in logical screen */
PRUint32 aFrameWidth,
PRUint32 aFrameHeight,
GIF_RGB* aTransparencyChromaKey);
static int PR_CALLBACK EndImageFrame(
void* aClientData,
PRUint32 aFrameNumber,
PRUint32 aDelayTimeout);
static int PR_CALLBACK SetupColorspaceConverter();
static int PR_CALLBACK ResetPalette();
static int PR_CALLBACK InitTransparentPixel();
static int PR_CALLBACK DestroyTransparentPixel();
static int PR_CALLBACK HaveImageAll(
void* aClientData);
#endif

View File

@@ -0,0 +1,41 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Chris Saari <saari@netscape.com>
*/
#include "nsGIFDecoder2.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsISupports.h"
#include "nsCOMPtr.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsGIFDecoder2)
static nsModuleComponentInfo components[] =
{
{ "GIF Decoder",
NS_GIFDECODER2_CID,
"@mozilla.org/image/decoder;2?type=image/gif",
nsGIFDecoder2Constructor, },
};
NS_IMPL_NSGETMODULE("nsGIFModule2", components)

View File

@@ -0,0 +1,18 @@
?AddRef@nsGIFDecoder2@@UAGKXZ ; 2550
?Release@nsGIFDecoder2@@UAGKXZ ; 2550
?gif_write_ready@@YAEPAUgif_struct@@@Z ; 1624
?ProcessData@nsGIFDecoder2@@QAGIPAEI@Z ; 1624
?gif_write@@YAHPAUgif_struct@@PBEI@Z ; 1624
?WriteFrom@nsGIFDecoder2@@UAGIPAVnsIInputStream@@IPAI@Z ; 1309
?Close@nsGIFDecoder2@@UAGIXZ ; 1275
??_GnsGIFDecoder2@@UAEPAXI@Z ; 1275
??0nsGIFDecoder2@@QAE@XZ ; 1275
??1nsGIFDecoder2@@UAE@XZ ; 1275
?QueryInterface@nsGIFDecoder2@@UAGIABUnsID@@PAPAX@Z ; 1275
?GIFInit@@YAHPAUgif_struct@@PAXP6AHXZP6AH1IIE@ZP6AH1H@ZP6AH1IIIIIPAU_GIF_RGB@@@ZP6AH1II@Z2222P6AH1PAE8HHHHEH@ZP6AH1@Z@Z ; 1275
?Init@nsGIFDecoder2@@UAGIPAVimgIRequest@@@Z ; 1275
?Flush@nsGIFDecoder2@@UAGIXZ ; 1275
?gif_destroy@@YAXPAUgif_struct@@@Z ; 1275
?gif_create@@YAHPAPAUgif_struct@@@Z ; 1275
?il_BACat@@YAPADPAPADIPBDI@Z ; 698
_NSGetModule ; 1

View File

@@ -0,0 +1,378 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Brian Ryner.
* Portions created by Brian Ryner are Copyright (C) 2000 Brian Ryner.
* All Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
*/
#include "nsIconChannel.h"
#include "nsIServiceManager.h"
#include "nsIInterfaceRequestor.h"
#include "nsXPIDLString.h"
#include "nsMimeTypes.h"
#include "nsMemory.h"
#include "nsIStringStream.h"
#include "nsIURL.h"
#include "nsNetUtil.h"
#include "nsIMimeService.h"
#include "nsCExternalHandlerService.h"
#include "plstr.h"
#include <Files.h>
#include <QuickDraw.h>
// nsIconChannel methods
nsIconChannel::nsIconChannel()
{
NS_INIT_REFCNT();
mStatus = NS_OK;
}
nsIconChannel::~nsIconChannel()
{}
NS_IMPL_THREADSAFE_ISUPPORTS2(nsIconChannel,
nsIChannel,
nsIRequest)
nsresult nsIconChannel::Init(nsIURI* uri)
{
nsresult rv;
NS_ASSERTION(uri, "no uri");
mUrl = uri;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIRequest methods:
NS_IMETHODIMP nsIconChannel::GetName(PRUnichar* *result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconChannel::IsPending(PRBool *result)
{
NS_NOTREACHED("nsIconChannel::IsPending");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconChannel::GetStatus(nsresult *status)
{
*status = mStatus;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::Cancel(nsresult status)
{
NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code");
nsresult rv = NS_ERROR_FAILURE;
mStatus = status;
return rv;
}
NS_IMETHODIMP nsIconChannel::Suspend(void)
{
NS_NOTREACHED("nsIconChannel::Suspend");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconChannel::Resume(void)
{
NS_NOTREACHED("nsIconChannel::Resume");
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
// nsIChannel methods:
NS_IMETHODIMP nsIconChannel::GetOriginalURI(nsIURI* *aURI)
{
*aURI = mOriginalURI ? mOriginalURI : mUrl;
NS_ADDREF(*aURI);
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetOriginalURI(nsIURI* aURI)
{
mOriginalURI = aURI;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetURI(nsIURI* *aURI)
{
*aURI = mUrl;
NS_IF_ADDREF(*aURI);
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetURI(nsIURI* aURI)
{
mUrl = aURI;
return NS_OK;
}
NS_IMETHODIMP
nsIconChannel::Open(nsIInputStream **_retval)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt)
{
// get the file name from the url
nsXPIDLCString fileName; // will contain a dummy file we'll use to figure out the type of icon desired.
nsXPIDLCString filePath; // will contain an optional parameter for small vs. large icon. default is small
mUrl->GetHost(getter_Copies(fileName));
nsCOMPtr<nsIURL> url (do_QueryInterface(mUrl));
if (url)
url->GetFileBaseName(getter_Copies(filePath));
nsresult rv = NS_OK;
nsCOMPtr<nsIMIMEService> mimeService (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
// extract the extension out of the dummy file so we can look it up in the mime service.
char * chFileName = fileName.get(); // get the underlying buffer
char * fileExtension = PL_strrchr(chFileName, '.');
if (!fileExtension) return NS_ERROR_FAILURE; // no file extension to work from.
// look the file extension up in the registry.
nsCOMPtr<nsIMIMEInfo> mimeInfo;
mimeService->GetFromExtension(fileExtension, getter_AddRefs(mimeInfo));
NS_ENSURE_TRUE(mimeInfo, NS_ERROR_FAILURE);
// get the mac creator and file type for this mime object
PRUint32 macType;
PRUint32 macCreator;
mimeInfo->GetMacType(&macType);
mimeInfo->GetMacCreator(&macCreator);
// get a refernce to the desktop database
DTPBRec pb;
OSErr err = noErr;
memset(&pb, 0, sizeof(DTPBRec));
pb.ioCompletion = nil;
pb.ioVRefNum = 0; // default desktop volume
pb.ioNamePtr = nil;
err = PBDTGetPath(&pb);
if (err != noErr) return NS_ERROR_FAILURE;
pb.ioFileCreator = macCreator;
pb.ioFileType = macType;
pb.ioCompletion = nil;
pb.ioTagInfo = 0;
PRUint32 numPixelsInRow = 0;
if (filePath && !nsCRT::strcmp(filePath, "large"))
{
pb.ioDTReqCount = kLarge8BitIconSize;
pb.ioIconType = kLarge8BitIcon;
numPixelsInRow = 32;
}
else
{
pb.ioDTReqCount = kSmall8BitIconSize;
pb.ioIconType = kSmall8BitIcon;
numPixelsInRow = 16;
}
// allocate a buffer large enough to handle the icon
PRUint8 * bitmapData = (PRUint8 *) nsMemory::Alloc (pb.ioDTReqCount);
pb.ioDTBuffer = (Ptr) bitmapData;
err = PBDTGetIcon(&pb, false);
if (err != noErr) return NS_ERROR_FAILURE; // unable to fetch the icon....
nsCString iconBuffer;
iconBuffer.Assign((char) numPixelsInRow);
iconBuffer.Append((char) numPixelsInRow);
CTabHandle cTabHandle = GetCTable(72);
if (!cTabHandle) return NS_ERROR_FAILURE;
HLock((Handle) cTabHandle);
CTabPtr colTable = *cTabHandle;
RGBColor rgbCol;
PRUint8 redValue, greenValue, blueValue;
for (PRUint32 index = 0; index < pb.ioDTReqCount; index ++)
{
// each byte in bitmapData needs to be converted from an 8 bit system color into
// 24 bit RGB data which our special icon image decoder can understand.
ColorSpec colSpec = colTable->ctTable[ bitmapData[index]];
rgbCol = colSpec.rgb;
redValue = rgbCol.red & 0xff;
greenValue = rgbCol.green & 0xff;
blueValue = rgbCol.blue & 0xff;
// for some reason the image code on the mac expects each RGB pixel value to be padded with a preceding byte.
// so add the padding here....
iconBuffer.Append((char) 0);
iconBuffer.Append((char) redValue);
iconBuffer.Append((char) greenValue);
iconBuffer.Append((char) blueValue);
}
HUnlock((Handle) cTabHandle);
DisposeCTable(cTabHandle);
nsMemory::Free(bitmapData);
// now that the color bitmask is taken care of, we need to do the same thing again for the transparency
// bit mask....
if (filePath && !nsCRT::strcmp(filePath, "large"))
{
pb.ioDTReqCount = kLargeIconSize;
pb.ioIconType = kLargeIcon;
}
else
{
pb.ioDTReqCount = kSmallIconSize;
pb.ioIconType = kSmallIcon;
}
// allocate a buffer large enough to handle the icon
bitmapData = (PRUint8 *) nsMemory::Alloc (pb.ioDTReqCount);
pb.ioDTBuffer = (Ptr) bitmapData;
err = PBDTGetIcon(&pb, false);
PRUint32 index = pb.ioDTReqCount/2;
while (index < pb.ioDTReqCount)
{
iconBuffer.Append((char) bitmapData[index]);
iconBuffer.Append((char) bitmapData[index + 1]);
if (numPixelsInRow == 32)
{
iconBuffer.Append((char) bitmapData[index + 2]);
iconBuffer.Append((char) bitmapData[index + 3]);
index += 4;
}
else
{
iconBuffer.Append((char) 255); // 2 bytes of padding
iconBuffer.Append((char) 255);
index += 2;
}
}
nsMemory::Free(bitmapData);
// turn our nsString into a stream looking object...
aListener->OnStartRequest(this, ctxt);
// turn our string into a stream...
nsCOMPtr<nsISupports> streamSupports;
NS_NewByteInputStream(getter_AddRefs(streamSupports), iconBuffer.get(), iconBuffer.Length());
nsCOMPtr<nsIInputStream> inputStr (do_QueryInterface(streamSupports));
aListener->OnDataAvailable(this, ctxt, inputStr, 0, iconBuffer.Length());
aListener->OnStopRequest(this, ctxt, NS_OK, nsnull);
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetLoadAttributes(PRUint32 *aLoadAttributes)
{
*aLoadAttributes = mLoadAttributes;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetLoadAttributes(PRUint32 aLoadAttributes)
{
mLoadAttributes = aLoadAttributes;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetContentType(char* *aContentType)
{
if (!aContentType) return NS_ERROR_NULL_POINTER;
*aContentType = nsCRT::strdup("image/icon");
if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsIconChannel::SetContentType(const char *aContentType)
{
//It doesn't make sense to set the content-type on this type
// of channel...
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsIconChannel::GetContentLength(PRInt32 *aContentLength)
{
*aContentLength = mContentLength;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetContentLength(PRInt32 aContentLength)
{
NS_NOTREACHED("nsIconChannel::SetContentLength");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
{
*aLoadGroup = mLoadGroup;
NS_IF_ADDREF(*aLoadGroup);
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
{
mLoadGroup = aLoadGroup;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetOwner(nsISupports* *aOwner)
{
*aOwner = mOwner.get();
NS_IF_ADDREF(*aOwner);
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetOwner(nsISupports* aOwner)
{
mOwner = aOwner;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
{
*aNotificationCallbacks = mCallbacks.get();
NS_IF_ADDREF(*aNotificationCallbacks);
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
{
mCallbacks = aNotificationCallbacks;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
{
*aSecurityInfo = nsnull;
return NS_OK;
}

View File

@@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Brian Ryner.
* Portions created by Brian Ryner are Copyright (C) 2000 Brian Ryner.
* All Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
*/
#ifndef nsIconChannel_h___
#define nsIconChannel_h___
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsIChannel.h"
#include "nsILoadGroup.h"
#include "nsIInterfaceRequestor.h"
#include "nsIURI.h"
class nsIconChannel : public nsIChannel
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
nsIconChannel();
virtual ~nsIconChannel();
nsresult Init(nsIURI* uri);
protected:
nsCOMPtr<nsIURI> mUrl;
nsCOMPtr<nsIURI> mOriginalURI;
PRUint32 mLoadAttributes;
PRInt32 mContentLength;
nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
nsCOMPtr<nsISupports> mOwner;
nsresult mStatus;
};
#endif /* nsIconChannel_h___ */

View File

@@ -0,0 +1,62 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Scott MacGregor <mscott@netscape.com>
#
DEPTH=..\..\..\..
include <$(DEPTH)/config/config.mak>
DIR=win
MODULE = imgicon
LIBRARY_NAME = imgicon
DLL = $(OBJDIR)\$(LIBRARY_NAME).dll
MAKE_OBJ_TYPE = DLL
OBJS = \
.\$(OBJDIR)\nsIconDecoder.obj \
.\$(OBJDIR)\nsIconModule.obj \
.\$(OBJDIR)\nsIconProtocolHandler.obj \
$(NULL)
LLIBS=\
$(LIBNSPR) \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\gkgfxwin.lib \
$(DIST)\lib\imgiconwin_s.lib \
$(NULL)
WIN_LIBS= shell32.lib
INCS = $(INCS) \
-I$(DEPTH)\dist\include \
-I$(DEPTH)\modules\libpr0n\decoders\icon\win \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(LIBRARY_NAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(LIBRARY_NAME).lib $(DIST)\lib
clobber::
rm -f $(DIST)\bin\components\$(LIBRARY_NAME).dll
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,195 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
*
*/
#include "nsIconDecoder.h"
#include "nsIInputStream.h"
#include "imgIContainer.h"
#include "imgIContainerObserver.h"
#include "nspr.h"
#include "nsIComponentManager.h"
#include "nsRect.h"
NS_IMPL_THREADSAFE_ADDREF(nsIconDecoder);
NS_IMPL_THREADSAFE_RELEASE(nsIconDecoder);
NS_INTERFACE_MAP_BEGIN(nsIconDecoder)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIOutputStream)
NS_INTERFACE_MAP_ENTRY(nsIOutputStream)
NS_INTERFACE_MAP_ENTRY(imgIDecoder)
NS_INTERFACE_MAP_END_THREADSAFE
nsIconDecoder::nsIconDecoder()
{
NS_INIT_ISUPPORTS();
}
nsIconDecoder::~nsIconDecoder()
{ }
/** imgIDecoder methods **/
NS_IMETHODIMP nsIconDecoder::Init(imgIRequest *aRequest)
{
mRequest = aRequest;
mObserver = do_QueryInterface(aRequest); // we're holding 2 strong refs to the request.
aRequest->GetImage(getter_AddRefs(mImage));
mFrame = do_CreateInstance("@mozilla.org/gfx/image/frame;2");
if (!mFrame) return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP nsIconDecoder::GetRequest(imgIRequest * *aRequest)
{
*aRequest = mRequest;
NS_ADDREF(*aRequest);
return NS_OK;
}
/** nsIOutputStream methods **/
NS_IMETHODIMP nsIconDecoder::Close()
{
if (mObserver)
{
mObserver->OnStopFrame(nsnull, nsnull, mFrame);
mObserver->OnStopContainer(nsnull, nsnull, mImage);
mObserver->OnStopDecode(nsnull, nsnull, NS_OK, nsnull);
}
return NS_OK;
}
NS_IMETHODIMP nsIconDecoder::Flush()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconDecoder::Write(const char *buf, PRUint32 count, PRUint32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconDecoder::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval)
{
nsresult rv;
char *buf = (char *)PR_Malloc(count);
if (!buf) return NS_ERROR_OUT_OF_MEMORY; /* we couldn't allocate the object */
// read the data from the input stram...
PRUint32 readLen;
rv = inStr->Read(buf, count, &readLen);
char *data = buf;
if (NS_FAILED(rv)) return rv;
// since WriteFrom is only called once, go ahead and fire the on start notifications..
mObserver->OnStartDecode(nsnull, nsnull);
PRUint32 i = 0;
// Read size
PRInt32 w, h;
w = data[0];
h = data[1];
data += 2;
readLen -= i + 2;
mImage->Init(w, h, mObserver);
if (mObserver)
mObserver->OnStartContainer(nsnull, nsnull, mImage);
mFrame->Init(0, 0, w, h, gfxIFormats::RGB_A1);
mImage->AppendFrame(mFrame);
if (mObserver)
mObserver->OnStartFrame(nsnull, nsnull, mFrame);
PRUint32 bpr, abpr;
nscoord width, height;
mFrame->GetImageBytesPerRow(&bpr);
mFrame->GetAlphaBytesPerRow(&abpr);
mFrame->GetWidth(&width);
mFrame->GetHeight(&height);
i = 0;
PRInt32 rownum = 0; // XXX this better not have a decimal
PRInt32 wroteLen = 0;
do
{
PRUint8 *line = (PRUint8*)data + i*bpr;
mFrame->SetImageData(line, bpr, (rownum++)*bpr);
nsRect r(0, rownum, width, 1);
mObserver->OnDataAvailable(nsnull, nsnull, mFrame, &r);
wroteLen += bpr ;
i++;
} while(rownum < height);
// now we want to send in the alpha data...
for (rownum = 0; rownum < height; rownum ++)
{
PRUint8 * line = (PRUint8*) data + abpr * rownum + height*bpr;
mFrame->SetAlphaData(line, abpr, (rownum)*abpr);
}
PR_FREEIF(buf);
return NS_OK;
}
NS_IMETHODIMP nsIconDecoder::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconDecoder::GetNonBlocking(PRBool *aNonBlocking)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconDecoder::SetNonBlocking(PRBool aNonBlocking)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconDecoder::GetObserver(nsIOutputStreamObserver * *aObserver)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconDecoder::SetObserver(nsIOutputStreamObserver * aObserver)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
*/
#ifndef nsIconDecoder_h__
#define nsIconDecoder_h__
#include "imgIDecoder.h"
#include "nsCOMPtr.h"
#include "imgIContainer.h"
#include "imgIDecoderObserver.h"
#include "gfxIImageFrame.h"
#include "imgIRequest.h"
#define NS_ICONDECODER_CID \
{ /* FFC08380-256C-11d5-9905-001083010E9B */ \
0xffc08380, \
0x256c, \
0x11d5, \
{ 0x99, 0x5, 0x0, 0x10, 0x83, 0x1, 0xe, 0x9b } \
}
//////////////////////////////////////////////////////////////////////////////////////////////
// The icon decoder is a decoder specifically tailored for loading icons
// from the OS. We've defined our own little format to represent these icons
// and this decoder takes that format and converts it into 24-bit RGB with alpha channel
// support. It was modeled a bit off the PPM decoder.
//
// Assumptions about the decoder:
// (1) We receive ALL of the data from the icon channel in one OnDataAvailable call. We don't
// support multiple ODA calls yet.
// (2) the format of the incoming data is as follows:
// The first two bytes contain the width and the height of the icon.
// Followed by 3 bytes per pixel for the color bitmap row after row. (for heigh * width * 3 bytes)
// Followed by bit mask data (used for transparency on the alpha channel).
//
//
//////////////////////////////////////////////////////////////////////////////////////////////
class nsIconDecoder : public imgIDecoder
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMGIDECODER
NS_DECL_NSIOUTPUTSTREAM
nsIconDecoder();
virtual ~nsIconDecoder();
private:
nsCOMPtr<imgIContainer> mImage;
nsCOMPtr<gfxIImageFrame> mFrame;
nsCOMPtr<imgIRequest> mRequest;
nsCOMPtr<imgIDecoderObserver> mObserver; // this is just qi'd from mRequest for speed
};
#endif // nsIconDecoder_h__

View File

@@ -0,0 +1,54 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
*/
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsIconDecoder.h"
#include "nsIconProtocolHandler.h"
// objects that just require generic constructors
/******************************************************************************
* Protocol CIDs
*/
#define NS_ICONPROTOCOL_CID { 0xd0f9db12, 0x249c, 0x11d5, { 0x99, 0x5, 0x0, 0x10, 0x83, 0x1, 0xe, 0x9b } }
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIconDecoder)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIconProtocolHandler)
static nsModuleComponentInfo components[] =
{
{ "icon decoder",
NS_ICONDECODER_CID,
"@mozilla.org/image/decoder;2?type=image/icon",
nsIconDecoderConstructor, },
{ "Icon Protocol Handler",
NS_ICONPROTOCOL_CID,
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "icon",
nsIconProtocolHandlerConstructor
}
};
NS_IMPL_NSGETMODULE("nsIconDecoderModule", components)

View File

@@ -0,0 +1,90 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Brian Ryner.
* Portions created by Brian Ryner are Copyright (C) 2000 Brian Ryner.
* All Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
*/
#include "nsIconChannel.h"
#include "nsIconProtocolHandler.h"
#include "nsIURL.h"
#include "nsCRT.h"
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kStandardURICID, NS_STANDARDURL_CID);
////////////////////////////////////////////////////////////////////////////////
nsIconProtocolHandler::nsIconProtocolHandler()
{
NS_INIT_REFCNT();
}
nsIconProtocolHandler::~nsIconProtocolHandler()
{}
NS_IMPL_ISUPPORTS2(nsIconProtocolHandler, nsIProtocolHandler, nsISupportsWeakReference)
////////////////////////////////////////////////////////////////////////////////
// nsIProtocolHandler methods:
NS_IMETHODIMP nsIconProtocolHandler::GetScheme(char* *result)
{
*result = nsCRT::strdup("icon");
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP nsIconProtocolHandler::GetDefaultPort(PRInt32 *result)
{
*result = 0;
return NS_OK;
}
NS_IMETHODIMP nsIconProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI **result)
{
nsresult rv;
// no concept of a relative icon url
NS_ASSERTION(!aBaseURI, "base url passed into icon protocol handler");
nsCOMPtr<nsIURI> url = do_CreateInstance(kStandardURICID, &rv);
if (NS_FAILED(rv)) return rv;
rv = url->SetSpec((char*)aSpec);
*result = url;
NS_IF_ADDREF(*result);
return rv;
}
NS_IMETHODIMP nsIconProtocolHandler::NewChannel(nsIURI* url, nsIChannel* *result)
{
nsCOMPtr<nsIChannel> channel;
NS_NEWXPCOM(channel, nsIconChannel);
if (channel)
NS_STATIC_CAST(nsIconChannel*,NS_STATIC_CAST(nsIChannel*, channel))->Init(url);
*result = channel;
NS_IF_ADDREF(*result);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,43 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
*/
#ifndef nsIconProtocolHandler_h___
#define nsIconProtocolHandler_h___
#include "nsWeakReference.h"
#include "nsIProtocolHandler.h"
class nsIconProtocolHandler : public nsIProtocolHandler, public nsSupportsWeakReference
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPROTOCOLHANDLER
// nsIconProtocolHandler methods:
nsIconProtocolHandler();
virtual ~nsIconProtocolHandler();
protected:
};
#endif /* nsIconProtocolHandler_h___ */

View File

@@ -0,0 +1,46 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Scott MacGregor <mscott@netscape.com>
DEPTH=..\..\..\..\..
MODULE=imgicon
LIBRARY_NAME=imgiconwin_s
CPP_OBJS=\
.\$(OBJDIR)\nsIconChannel.obj \
$(NULL)
INCS = $(INCS) \
-I$(DEPTH)\dist\include \
-I..\ \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,377 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Brian Ryner.
* Portions created by Brian Ryner are Copyright (C) 2000 Brian Ryner.
* All Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
*/
#include "nsIconChannel.h"
#include "nsIServiceManager.h"
#include "nsIInterfaceRequestor.h"
#include "nsXPIDLString.h"
#include "nsMimeTypes.h"
#include "nsMemory.h"
#include "nsIStringStream.h"
#include "nsIURL.h"
#include "nsNetUtil.h"
// we need windows.h to read out registry information...
#include <windows.h>
#include <shellapi.h>
// nsIconChannel methods
nsIconChannel::nsIconChannel()
{
NS_INIT_REFCNT();
mStatus = NS_OK;
}
nsIconChannel::~nsIconChannel()
{}
NS_IMPL_THREADSAFE_ISUPPORTS2(nsIconChannel,
nsIChannel,
nsIRequest)
nsresult nsIconChannel::Init(nsIURI* uri)
{
nsresult rv;
NS_ASSERTION(uri, "no uri");
mUrl = uri;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIRequest methods:
NS_IMETHODIMP nsIconChannel::GetName(PRUnichar* *result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconChannel::IsPending(PRBool *result)
{
NS_NOTREACHED("nsIconChannel::IsPending");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconChannel::GetStatus(nsresult *status)
{
*status = mStatus;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::Cancel(nsresult status)
{
NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code");
nsresult rv = NS_ERROR_FAILURE;
mStatus = status;
return rv;
}
NS_IMETHODIMP nsIconChannel::Suspend(void)
{
NS_NOTREACHED("nsIconChannel::Suspend");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconChannel::Resume(void)
{
NS_NOTREACHED("nsIconChannel::Resume");
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
// nsIChannel methods:
NS_IMETHODIMP nsIconChannel::GetOriginalURI(nsIURI* *aURI)
{
*aURI = mOriginalURI ? mOriginalURI : mUrl;
NS_ADDREF(*aURI);
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetOriginalURI(nsIURI* aURI)
{
mOriginalURI = aURI;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetURI(nsIURI* *aURI)
{
*aURI = mUrl;
NS_IF_ADDREF(*aURI);
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetURI(nsIURI* aURI)
{
mUrl = aURI;
return NS_OK;
}
NS_IMETHODIMP
nsIconChannel::Open(nsIInputStream **_retval)
{
return NS_ERROR_FAILURE;
}
void InvertRows(unsigned char * aInitialBuffer, PRUint32 sizeOfBuffer, PRUint32 numBytesPerRow)
{
PRUint32 numRows = sizeOfBuffer / numBytesPerRow;
void * temporaryRowHolder = (void *) nsMemory::Alloc(numBytesPerRow);
PRUint32 currentRow = 0;
PRUint32 lastRow = (numRows - 1) * numBytesPerRow;
while (currentRow < lastRow)
{
// store the current row into a temporary buffer
nsCRT::memcpy(temporaryRowHolder, (void *) &aInitialBuffer[currentRow], numBytesPerRow);
nsCRT::memcpy((void *) &aInitialBuffer[currentRow], (void *)&aInitialBuffer[lastRow], numBytesPerRow);
nsCRT::memcpy((void *) &aInitialBuffer[lastRow], temporaryRowHolder, numBytesPerRow);
lastRow -= numBytesPerRow;
currentRow += numBytesPerRow;
}
}
NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt)
{
// get the file name from the url
nsXPIDLCString fileName; // will contain a dummy file we'll use to figure out the type of icon desired.
nsXPIDLCString filePath; // will contain an optional parameter for small vs. large icon. default is small
mUrl->GetHost(getter_Copies(fileName));
nsCOMPtr<nsIURL> url (do_QueryInterface(mUrl));
if (url)
url->GetFileBaseName(getter_Copies(filePath));
// 1) get a hIcon for the file.
SHFILEINFO sfi;
UINT infoFlags = SHGFI_USEFILEATTRIBUTES | SHGFI_ICON;
if (filePath && !nsCRT::strcmp(filePath, "large"))
infoFlags |= SHGFI_LARGEICON;
else // default to small
infoFlags |= SHGFI_SMALLICON;
LONG result= SHGetFileInfo(fileName, FILE_ATTRIBUTE_ARCHIVE, &sfi, sizeof(sfi), infoFlags);
if (result > 0 && sfi.hIcon)
{
// we got a handle to an icon. Now we want to get a bitmap for the icon using GetIconInfo....
ICONINFO pIconInfo;
result = GetIconInfo(sfi.hIcon, &pIconInfo);
if (result > 0)
{
// now we have the bit map we need to get info about the bitmap
BITMAPINFO pBitMapInfo;
BITMAPINFOHEADER pBitMapInfoHeader;
pBitMapInfo.bmiHeader.biBitCount = 0;
pBitMapInfo.bmiHeader.biSize = sizeof(pBitMapInfoHeader);
HDC pDC = CreateCompatibleDC(NULL); // get a device context for the screen.
result = GetDIBits(pDC, pIconInfo.hbmColor, 0, 0, NULL, &pBitMapInfo, DIB_RGB_COLORS);
if (result > 0 && pBitMapInfo.bmiHeader.biSizeImage > 0)
{
// allocate a buffer to hold the bit map....this should be a buffer that's biSizeImage...
unsigned char * buffer = (PRUint8 *) nsMemory::Alloc(pBitMapInfo.bmiHeader.biSizeImage);
result = GetDIBits(pDC, pIconInfo.hbmColor, 0, pBitMapInfo.bmiHeader.biHeight, (void *) buffer, &pBitMapInfo, DIB_RGB_COLORS);
if (result > 0)
{
PRUint32 bytesPerPixel = pBitMapInfo.bmiHeader.biBitCount / 8;
InvertRows(buffer, pBitMapInfo.bmiHeader.biSizeImage, pBitMapInfo.bmiHeader.biWidth * bytesPerPixel);
// Convert our little icon buffer which is padded to 4 bytes per pixel into a nice 3 byte per pixel
// description.
nsCString iconBuffer;
iconBuffer.Assign((char) pBitMapInfo.bmiHeader.biWidth);
iconBuffer.Append((char) pBitMapInfo.bmiHeader.biHeight);
PRInt32 index = 0;
if (pBitMapInfo.bmiHeader.biBitCount == 16)
{
PRUint8 redValue, greenValue, blueValue, partialGreen;
while (index < pBitMapInfo.bmiHeader.biSizeImage)
{
DWORD dst=(DWORD) buffer[index];
PRUint16 num = 0;
num = (PRUint8) buffer[index];
num <<= 8;
num |= (PRUint8) buffer[index+1];
//blueValue = (PRUint8)((*dst)&(0x1F));
//greenValue = (PRUint8)(((*dst)>>5)&(0x1F));
//redValue = (PRUint8)(((*dst)>>10)&(0x1F));
redValue = ((PRUint32) (((float)(num & 0x7c00) / 0x7c00) * 0xFF0000) & 0xFF0000)>> 16;
greenValue = ((PRUint32)(((float)(num & 0x03E0) / 0x03E0) * 0x00FF00) & 0x00FF00)>> 8;
blueValue = ((PRUint32)(((float)(num & 0x001F) / 0x001F) * 0x0000FF) & 0x0000FF);
// now we have the right RGB values...
iconBuffer.Append((char) redValue);
iconBuffer.Append((char) greenValue);
iconBuffer.Append((char) blueValue);
index += bytesPerPixel;
}
}
else
{
while (index <pBitMapInfo.bmiHeader.biSizeImage)
{
iconBuffer.Append((char) buffer[index]);
iconBuffer.Append((char) buffer[index+1]);
iconBuffer.Append((char) buffer[index+2]);
index += bytesPerPixel;
}
}
// now we need to tack on the alpha data...which is hbmMask
pBitMapInfo.bmiHeader.biBitCount = 0;
pBitMapInfo.bmiHeader.biSize = sizeof(pBitMapInfoHeader);
result = GetDIBits(pDC, pIconInfo.hbmMask, 0, 0, NULL, &pBitMapInfo, DIB_RGB_COLORS);
if (result > 0 && pBitMapInfo.bmiHeader.biSizeImage > 0)
{
// allocate a buffer to hold the bit map....this should be a buffer that's biSizeImage...
unsigned char * maskBuffer = (PRUint8 *) nsMemory::Alloc(pBitMapInfo.bmiHeader.biSizeImage);
result = GetDIBits(pDC, pIconInfo.hbmMask, 0, pBitMapInfo.bmiHeader.biHeight, (void *) maskBuffer, &pBitMapInfo, DIB_RGB_COLORS);
if (result > 0)
{
InvertRows(maskBuffer, pBitMapInfo.bmiHeader.biSizeImage, 4);
index = 0;
// for some reason the bit mask on windows are flipped from the values we really want for transparency.
// So complement each byte in the bit mask.
while (index < pBitMapInfo.bmiHeader.biSizeImage)
{
maskBuffer[index]^=255;
index += 1;
}
iconBuffer.Append((char *) maskBuffer, pBitMapInfo.bmiHeader.biSizeImage);
}
nsMemory::Free(maskBuffer);
} // if we have a mask buffer to apply
// turn our nsString into a stream looking object...
aListener->OnStartRequest(this, ctxt);
// turn our string into a stream...
nsCOMPtr<nsISupports> streamSupports;
NS_NewByteInputStream(getter_AddRefs(streamSupports), iconBuffer.get(), iconBuffer.Length());
nsCOMPtr<nsIInputStream> inputStr (do_QueryInterface(streamSupports));
aListener->OnDataAvailable(this, ctxt, inputStr, 0, iconBuffer.Length());
aListener->OnStopRequest(this, ctxt, NS_OK, nsnull);
} // if we got valid bits for the main bitmap mask
nsMemory::Free(buffer);
}
DeleteDC(pDC);
}
}
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetLoadAttributes(PRUint32 *aLoadAttributes)
{
*aLoadAttributes = mLoadAttributes;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetLoadAttributes(PRUint32 aLoadAttributes)
{
mLoadAttributes = aLoadAttributes;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetContentType(char* *aContentType)
{
if (!aContentType) return NS_ERROR_NULL_POINTER;
*aContentType = nsCRT::strdup("image/icon");
if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsIconChannel::SetContentType(const char *aContentType)
{
//It doesn't make sense to set the content-type on this type
// of channel...
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsIconChannel::GetContentLength(PRInt32 *aContentLength)
{
*aContentLength = mContentLength;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetContentLength(PRInt32 aContentLength)
{
NS_NOTREACHED("nsIconChannel::SetContentLength");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsIconChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
{
*aLoadGroup = mLoadGroup;
NS_IF_ADDREF(*aLoadGroup);
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
{
mLoadGroup = aLoadGroup;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetOwner(nsISupports* *aOwner)
{
*aOwner = mOwner.get();
NS_IF_ADDREF(*aOwner);
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetOwner(nsISupports* aOwner)
{
mOwner = aOwner;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
{
*aNotificationCallbacks = mCallbacks.get();
NS_IF_ADDREF(*aNotificationCallbacks);
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
{
mCallbacks = aNotificationCallbacks;
return NS_OK;
}
NS_IMETHODIMP nsIconChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
{
*aSecurityInfo = nsnull;
return NS_OK;
}

View File

@@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Brian Ryner.
* Portions created by Brian Ryner are Copyright (C) 2000 Brian Ryner.
* All Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
*/
#ifndef nsIconChannel_h___
#define nsIconChannel_h___
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsIChannel.h"
#include "nsILoadGroup.h"
#include "nsIInterfaceRequestor.h"
#include "nsIURI.h"
class nsIconChannel : public nsIChannel
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
nsIconChannel();
virtual ~nsIconChannel();
nsresult Init(nsIURI* uri);
protected:
nsCOMPtr<nsIURI> mUrl;
nsCOMPtr<nsIURI> mOriginalURI;
PRUint32 mLoadAttributes;
PRInt32 mContentLength;
nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
nsCOMPtr<nsISupports> mOwner;
nsresult mStatus;
};
#endif /* nsIconChannel_h___ */

View File

@@ -0,0 +1,42 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = imgjpeg
LIBRARY_NAME = imgjpeg
IS_COMPONENT = 1
REQUIRES = xpcom string necko layout jpeg gfx2 imglib2
CPPSRCS = nsJPEGDecoder.cpp nsJPEGFactory.cpp
EXTRA_DSO_LDOPTS = $(JPEG_LIBS) $(ZLIB_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,52 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Stuart Parmenter <pavlov@netscape.com>
#
DEPTH=..\..\..\..
include <$(DEPTH)/config/config.mak>
MODULE = imgjpeg
LIBRARY_NAME = imgjpeg
DLL = $(OBJDIR)\$(LIBRARY_NAME).dll
MAKE_OBJ_TYPE = DLL
OBJS = \
.\$(OBJDIR)\nsJPEGDecoder.obj \
.\$(OBJDIR)\nsJPEGFactory.obj \
$(NULL)
LLIBS=\
$(LIBNSPR) \
$(DIST)\lib\jpeg3250.lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\gkgfxwin.lib \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(LIBRARY_NAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(LIBRARY_NAME).lib $(DIST)\lib
clobber::
rm -f $(DIST)\bin\components\$(LIBRARY_NAME).dll
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,829 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*
*/
#include "nsJPEGDecoder.h"
#include "nsIInputStream.h"
#include "nspr.h"
#include "nsCRT.h"
#include "nsIComponentManager.h"
#include "imgIContainerObserver.h"
#include "ImageLogging.h"
NS_IMPL_ISUPPORTS2(nsJPEGDecoder, imgIDecoder, nsIOutputStream)
#if defined(PR_LOGGING)
PRLogModuleInfo *gJPEGlog = PR_NewLogModule("JPEGDecoder");
#else
#define gJPEGlog
#endif
void PR_CALLBACK init_source (j_decompress_ptr jd);
boolean PR_CALLBACK fill_input_buffer (j_decompress_ptr jd);
void PR_CALLBACK skip_input_data (j_decompress_ptr jd, long num_bytes);
void PR_CALLBACK term_source (j_decompress_ptr jd);
void PR_CALLBACK my_error_exit (j_common_ptr cinfo);
/* Normal JFIF markers can't have more bytes than this. */
#define MAX_JPEG_MARKER_LENGTH (((PRUint32)1 << 16) - 1)
/* Possible states for JPEG source manager */
enum data_source_state {
READING_BACK = 0, /* Must be zero for init purposes */
READING_NEW
};
/*
* Implementation of a JPEG src object that understands our state machine
*/
typedef struct {
/* public fields; must be first in this struct! */
struct jpeg_source_mgr pub;
nsJPEGDecoder *decoder;
} decoder_source_mgr;
nsJPEGDecoder::nsJPEGDecoder()
{
NS_INIT_ISUPPORTS();
mState = JPEG_HEADER;
mFillState = READING_BACK;
mSamples = nsnull;
mSamples3 = nsnull;
mRGBPadRow = nsnull;
mRGBPadRowLength = 0;
mBytesToSkip = 0;
memset(&mInfo, 0, sizeof(jpeg_decompress_struct));
mCompletedPasses = 0;
mBuffer = nsnull;
mBufferLen = mBufferSize = 0;
mBackBuffer = nsnull;
mBackBufferLen = mBackBufferSize = mBackBufferUnreadLen = 0;
}
nsJPEGDecoder::~nsJPEGDecoder()
{
if (mBuffer)
PR_Free(mBuffer);
if (mBackBuffer)
PR_Free(mBackBuffer);
if (mRGBPadRow)
PR_Free(mRGBPadRow);
}
/** imgIDecoder methods **/
/* void init (in imgIRequest aRequest); */
NS_IMETHODIMP nsJPEGDecoder::Init(imgIRequest *aRequest)
{
mRequest = aRequest;
mObserver = do_QueryInterface(mRequest);
aRequest->GetImage(getter_AddRefs(mImage));
/* We set up the normal JPEG error routines, then override error_exit. */
mInfo.err = jpeg_std_error(&mErr.pub);
/* mInfo.err = jpeg_std_error(&mErr.pub); */
mErr.pub.error_exit = my_error_exit;
/* Establish the setjmp return context for my_error_exit to use. */
if (setjmp(mErr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and return.
*/
return NS_ERROR_FAILURE;
}
/* Step 1: allocate and initialize JPEG decompression object */
jpeg_create_decompress(&mInfo);
decoder_source_mgr *src;
if (mInfo.src == NULL) {
//mInfo.src = PR_NEWZAP(decoder_source_mgr);
src = PR_NEWZAP(decoder_source_mgr);
if (!src) {
return PR_FALSE;
}
mInfo.src = (struct jpeg_source_mgr *) src;
}
/* Step 2: specify data source (eg, a file) */
/* Setup callback functions. */
src->pub.init_source = init_source;
src->pub.fill_input_buffer = fill_input_buffer;
src->pub.skip_input_data = skip_input_data;
src->pub.resync_to_restart = jpeg_resync_to_restart;
src->pub.term_source = term_source;
src->decoder = this;
return NS_OK;
}
/* readonly attribute imgIRequest request; */
NS_IMETHODIMP nsJPEGDecoder::GetRequest(imgIRequest * *aRequest)
{
*aRequest = mRequest;
NS_ADDREF(*aRequest);
return NS_OK;
}
/** nsIOutputStream methods **/
/* void close (); */
NS_IMETHODIMP nsJPEGDecoder::Close()
{
PR_LOG(gJPEGlog, PR_LOG_DEBUG,
("[this=%p] nsJPEGDecoder::Close\n", this));
if (mState != JPEG_DONE && mState != JPEG_SINK_NON_JPEG_TRAILER)
NS_WARNING("Never finished decoding the JPEG.");
/* Step 8: Release JPEG decompression object */
/* This is an important step since it will release a good deal of memory. */
jpeg_destroy_decompress(&mInfo);
return NS_OK;
}
/* void flush (); */
NS_IMETHODIMP nsJPEGDecoder::Flush()
{
LOG_SCOPE(gJPEGlog, "nsJPEGDecoder::Flush");
PRUint32 ret;
if (mState != JPEG_DONE && mState != JPEG_SINK_NON_JPEG_TRAILER)
return this->WriteFrom(nsnull, 0, &ret);
return NS_OK;
}
/* unsigned long write (in string buf, in unsigned long count); */
NS_IMETHODIMP nsJPEGDecoder::Write(const char *buf, PRUint32 count, PRUint32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* unsigned long writeFrom (in nsIInputStream inStr, in unsigned long count); */
NS_IMETHODIMP nsJPEGDecoder::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval)
{
LOG_SCOPE_WITH_PARAM(gJPEGlog, "nsJPEGDecoder::WriteFrom", "count", count);
/* We use our private extension JPEG error handler.
* Note that this struct must live as long as the main JPEG parameter
* struct, to avoid dangling-pointer problems.
*/
// XXX above what is this?
if (inStr) {
if (!mBuffer) {
mBuffer = (JOCTET *)PR_Malloc(count);
mBufferSize = count;
} else if (count > mBufferSize) {
mBuffer = (JOCTET *)PR_Realloc(mBuffer, count);
mBufferSize = count;
}
nsresult rv = inStr->Read((char*)mBuffer, count, &mBufferLen);
*_retval = mBufferLen;
//nsresult rv = mOutStream->WriteFrom(inStr, count, _retval);
NS_ASSERTION(NS_SUCCEEDED(rv), "nsJPEGDecoder::WriteFrom -- mOutStream->WriteFrom failed");
}
// else no input stream.. Flush() ?
nsresult error_code = NS_ERROR_FAILURE;
/* Return here if there is a fatal error. */
if ((error_code = setjmp(mErr.setjmp_buffer)) != 0) {
return error_code;
}
PR_LOG(gJPEGlog, PR_LOG_DEBUG,
("[this=%p] nsJPEGDecoder::WriteFrom -- processing JPEG data\n", this));
decoder_source_mgr *src = NS_REINTERPRET_CAST(decoder_source_mgr *, mInfo.src);
switch (mState) {
case JPEG_HEADER:
{
LOG_SCOPE(gJPEGlog, "nsJPEGDecoder::WriteFrom -- entering JPEG_HEADER case");
/* Step 3: read file parameters with jpeg_read_header() */
if (jpeg_read_header(&mInfo, TRUE) == JPEG_SUSPENDED)
return NS_OK; /* I/O suspension */
/*
* Don't allocate a giant and superfluous memory buffer
* when the image is a sequential JPEG.
*/
mInfo.buffered_image = jpeg_has_multiple_scans(&mInfo);
/* Used to set up image size so arrays can be allocated */
jpeg_calc_output_dimensions(&mInfo);
mObserver->OnStartDecode(nsnull, nsnull);
mImage->Init(mInfo.image_width, mInfo.image_height, mObserver);
mObserver->OnStartContainer(nsnull, nsnull, mImage);
mFrame = do_CreateInstance("@mozilla.org/gfx/image/frame;2");
gfx_format format;
#ifdef XP_PC
format = gfxIFormats::BGR;
#else
format = gfxIFormats::RGB;
#endif
mFrame->Init(0, 0, mInfo.image_width, mInfo.image_height, format);
mImage->AppendFrame(mFrame);
mObserver->OnStartFrame(nsnull, nsnull, mFrame);
/*
* Make a one-row-high sample array that will go away
* when done with image. Always make it big enough to
* hold an RGB row. Since this uses the IJG memory
* manager, it must be allocated before the call to
* jpeg_start_compress().
*/
int row_stride;
if(mInfo.output_components == 1)
row_stride = mInfo.output_width;
else
row_stride = mInfo.output_width * 4; // use 4 instead of mInfo.output_components
// so we don't have to fuss with byte alignment.
// Mac wants 4 anyways.
mSamples = (*mInfo.mem->alloc_sarray)((j_common_ptr) &mInfo,
JPOOL_IMAGE,
row_stride, 1);
#if defined(XP_PC) || defined(XP_MAC)
// allocate buffer to do byte flipping if needed
if (mInfo.output_components == 3) {
mRGBPadRow = (PRUint8*) PR_MALLOC(row_stride);
mRGBPadRowLength = row_stride;
memset(mRGBPadRow, 0, mRGBPadRowLength);
}
#endif
/* Allocate RGB buffer for conversion from greyscale. */
if (mInfo.output_components != 3) {
row_stride = mInfo.output_width * 4;
mSamples3 = (*mInfo.mem->alloc_sarray)((j_common_ptr) &mInfo,
JPOOL_IMAGE,
row_stride, 1);
}
mState = JPEG_START_DECOMPRESS;
}
case JPEG_START_DECOMPRESS:
{
LOG_SCOPE(gJPEGlog, "nsJPEGDecoder::WriteFrom -- entering JPEG_START_DECOMPRESS case");
/* Step 4: set parameters for decompression */
/* FIXME -- Should reset dct_method and dither mode
* for final pass of progressive JPEG
*/
mInfo.dct_method = JDCT_FASTEST;
mInfo.dither_mode = JDITHER_ORDERED;
mInfo.do_fancy_upsampling = FALSE;
mInfo.enable_2pass_quant = FALSE;
mInfo.do_block_smoothing = TRUE;
/* Step 5: Start decompressor */
if (jpeg_start_decompress(&mInfo) == FALSE)
return NS_OK; /* I/O suspension */
/* If this is a progressive JPEG ... */
if (mInfo.buffered_image) {
mState = JPEG_DECOMPRESS_PROGRESSIVE;
} else {
mState = JPEG_DECOMPRESS_SEQUENTIAL;
}
}
case JPEG_DECOMPRESS_SEQUENTIAL:
{
if (mState == JPEG_DECOMPRESS_SEQUENTIAL)
{
LOG_SCOPE(gJPEGlog, "nsJPEGDecoder::WriteFrom -- JPEG_DECOMPRESS_SEQUENTIAL case");
if (OutputScanlines(-1) == PR_FALSE)
return NS_OK; /* I/O suspension */
/* If we've completed image output ... */
NS_ASSERTION(mInfo.output_scanline == mInfo.output_height, "We didn't process all of the data!");
mState = JPEG_DONE;
}
}
case JPEG_DECOMPRESS_PROGRESSIVE:
{
if (mState == JPEG_DECOMPRESS_PROGRESSIVE)
{
LOG_SCOPE(gJPEGlog, "nsJPEGDecoder::WriteFrom -- JPEG_DECOMPRESS_PROGRESSIVE case");
int status;
do {
status = jpeg_consume_input(&mInfo);
} while (!((status == JPEG_SUSPENDED) ||
(status == JPEG_REACHED_EOI)));
switch (status) {
case JPEG_REACHED_EOI:
// End of image
mState = JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT;
break;
case JPEG_SUSPENDED:
PR_LOG(gJPEGlog, PR_LOG_DEBUG,
("[this=%p] nsJPEGDecoder::WriteFrom -- suspending\n", this));
return NS_OK; /* I/O suspension */
default:
printf("got someo other state!?\n");
}
}
}
case JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT:
{
if (mState == JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT)
{
LOG_SCOPE(gJPEGlog, "nsJPEGDecoder::WriteFrom -- entering JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT case");
// XXX progressive? ;)
// not really progressive according to the state machine... -saari
jpeg_start_output(&mInfo, mInfo.input_scan_number);
if (OutputScanlines(-1) == PR_FALSE)
return NS_OK; /* I/O suspension */
jpeg_finish_output(&mInfo);
mState = JPEG_DONE;
}
}
case JPEG_DONE:
{
LOG_SCOPE(gJPEGlog, "nsJPEGDecoder::WriteFrom -- entering JPEG_DONE case");
/* Step 7: Finish decompression */
if (jpeg_finish_decompress(&mInfo) == FALSE)
return NS_OK; /* I/O suspension */
mState = JPEG_SINK_NON_JPEG_TRAILER;
/* we're done dude */
break;
}
case JPEG_SINK_NON_JPEG_TRAILER:
PR_LOG(gJPEGlog, PR_LOG_DEBUG,
("[this=%p] nsJPEGDecoder::WriteFrom -- entering JPEG_SINK_NON_JPEG_TRAILER case\n", this));
break;
}
return NS_OK;
}
int
nsJPEGDecoder::OutputScanlines(int num_scanlines)
{
int pass = 0;
if (mState == JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT)
pass = -1;
else
pass = mCompletedPasses + 1;
while ((mInfo.output_scanline < mInfo.output_height) && num_scanlines--) {
JSAMPROW samples;
/* Request one scanline. Returns 0 or 1 scanlines. */
int ns = jpeg_read_scanlines(&mInfo, mSamples, 1);
if (ns != 1) {
return PR_FALSE; /* suspend */
}
/* If grayscale image ... */
if (mInfo.output_components == 1) {
JSAMPLE j;
JSAMPLE *j1 = mSamples[0];
const JSAMPLE *j1end = j1 + mInfo.output_width;
JSAMPLE *j3 = mSamples3[0];
/* Convert from grayscale to RGB. */
while (j1 < j1end) {
#ifdef XP_MAC
j = *j1++;
j3[0] = 0;
j3[1] = j;
j3[2] = j;
j3[3] = j;
j3 += 4;
#else
j = *j1++;
j3[0] = j;
j3[1] = j;
j3[2] = j;
j3 += 3;
#endif
}
samples = mSamples3[0];
} else {
/* 24-bit color image */
#ifdef XP_PC
memset(mRGBPadRow, 0, mInfo.output_width * 4);
PRUint8 *ptrOutputBuf = mRGBPadRow;
JSAMPLE *j1 = mSamples[0];
for (PRUint32 i=0;i<mInfo.output_width;++i) {
ptrOutputBuf[2] = *j1++;
ptrOutputBuf[1] = *j1++;
ptrOutputBuf[0] = *j1++;
ptrOutputBuf += 3;
}
samples = mRGBPadRow;
#else
#ifdef XP_MAC
memset(mRGBPadRow, 0, mInfo.output_width * 4);
PRUint8 *ptrOutputBuf = mRGBPadRow;
JSAMPLE *j1 = mSamples[0];
for (PRUint32 i=0;i<mInfo.output_width;++i) {
ptrOutputBuf[0] = 0;
ptrOutputBuf[1] = *j1++;
ptrOutputBuf[2] = *j1++;
ptrOutputBuf[3] = *j1++;
ptrOutputBuf += 4;
}
samples = mRGBPadRow;
#else
samples = mSamples[0];
#endif
#endif
}
PRUint32 bpr;
mFrame->GetImageBytesPerRow(&bpr);
mFrame->SetImageData(
samples, // data
bpr, // length
(mInfo.output_scanline-1) * bpr); // offset
nsRect r(0, mInfo.output_scanline, mInfo.output_width, 1);
mObserver->OnDataAvailable(nsnull, nsnull, mFrame, &r);
}
return PR_TRUE;
}
/* [noscript] unsigned long writeSegments (in nsReadSegmentFun reader, in voidPtr closure, in unsigned long count); */
NS_IMETHODIMP nsJPEGDecoder::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute boolean nonBlocking; */
NS_IMETHODIMP nsJPEGDecoder::GetNonBlocking(PRBool *aNonBlocking)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsJPEGDecoder::SetNonBlocking(PRBool aNonBlocking)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute nsIOutputStreamObserver observer; */
NS_IMETHODIMP nsJPEGDecoder::GetObserver(nsIOutputStreamObserver * *aObserver)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsJPEGDecoder::SetObserver(nsIOutputStreamObserver * aObserver)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* Override the standard error method in the IJG JPEG decoder code. */
void PR_CALLBACK
my_error_exit (j_common_ptr cinfo)
{
nsresult error_code = NS_ERROR_FAILURE;
decoder_error_mgr *err = (decoder_error_mgr *) cinfo->err;
#if 0
#ifdef DEBUG
/*ptn fix later */
if (il_debug >= 1) {
char buffer[JMSG_LENGTH_MAX];
/* Create the message */
(*cinfo->err->format_message) (cinfo, buffer);
ILTRACE(1,("%s\n", buffer));
}
#endif
/* Convert error to a browser error code */
if (cinfo->err->msg_code == JERR_OUT_OF_MEMORY)
error_code = MK_OUT_OF_MEMORY;
else
error_code = MK_IMAGE_LOSSAGE;
#endif
char buffer[JMSG_LENGTH_MAX];
/* Create the message */
(*cinfo->err->format_message) (cinfo, buffer);
fprintf(stderr, "my_error_exit()\n%s\n", buffer);
/* Return control to the setjmp point. */
longjmp(err->setjmp_buffer, error_code);
}
/******************************************************************************/
/*-----------------------------------------------------------------------------
* This is the callback routine from the IJG JPEG library used to supply new
* data to the decompressor when its input buffer is exhausted. It juggles
* multiple buffers in an attempt to avoid unnecessary copying of input data.
*
* (A simpler scheme is possible: It's much easier to use only a single
* buffer; when fill_input_buffer() is called, move any unconsumed data
* (beyond the current pointer/count) down to the beginning of this buffer and
* then load new data into the remaining buffer space. This approach requires
* a little more data copying but is far easier to get right.)
*
* At any one time, the JPEG decompressor is either reading from the necko
* input buffer, which is volatile across top-level calls to the IJG library,
* or the "backtrack" buffer. The backtrack buffer contains the remaining
* unconsumed data from the necko buffer after parsing was suspended due
* to insufficient data in some previous call to the IJG library.
*
* When suspending, the decompressor will back up to a convenient restart
* point (typically the start of the current MCU). The variables
* next_input_byte & bytes_in_buffer indicate where the restart point will be
* if the current call returns FALSE. Data beyond this point must be
* rescanned after resumption, so it must be preserved in case the decompressor
* decides to backtrack.
*
* Returns:
* TRUE if additional data is available, FALSE if no data present and
* the JPEG library should therefore suspend processing of input stream
*---------------------------------------------------------------------------*/
/******************************************************************************/
/* data source manager method
/******************************************************************************/
/******************************************************************************/
/* data source manager method
Initialize source. This is called by jpeg_read_header() before any
data is actually read. May leave
bytes_in_buffer set to 0 (in which case a fill_input_buffer() call
will occur immediately).
*/
void PR_CALLBACK
init_source (j_decompress_ptr jd)
{
}
/******************************************************************************/
/* data source manager method
Skip num_bytes worth of data. The buffer pointer and count should
be advanced over num_bytes input bytes, refilling the buffer as
needed. This is used to skip over a potentially large amount of
uninteresting data (such as an APPn marker). In some applications
it may be possible to optimize away the reading of the skipped data,
but it's not clear that being smart is worth much trouble; large
skips are uncommon. bytes_in_buffer may be zero on return.
A zero or negative skip count should be treated as a no-op.
*/
void PR_CALLBACK
skip_input_data (j_decompress_ptr jd, long num_bytes)
{
decoder_source_mgr *src = (decoder_source_mgr *)jd->src;
if (num_bytes > (long)src->pub.bytes_in_buffer) {
/*
* Can't skip it all right now until we get more data from
* network stream. Set things up so that fill_input_buffer
* will skip remaining amount.
*/
src->decoder->mBytesToSkip = (size_t)num_bytes - src->pub.bytes_in_buffer;
src->pub.next_input_byte += src->pub.bytes_in_buffer;
src->pub.bytes_in_buffer = 0;
} else {
/* Simple case. Just advance buffer pointer */
src->pub.bytes_in_buffer -= (size_t)num_bytes;
src->pub.next_input_byte += num_bytes;
}
}
/******************************************************************************/
/* data source manager method
This is called whenever bytes_in_buffer has reached zero and more
data is wanted. In typical applications, it should read fresh data
into the buffer (ignoring the current state of next_input_byte and
bytes_in_buffer), reset the pointer & count to the start of the
buffer, and return TRUE indicating that the buffer has been reloaded.
It is not necessary to fill the buffer entirely, only to obtain at
least one more byte. bytes_in_buffer MUST be set to a positive value
if TRUE is returned. A FALSE return should only be used when I/O
suspension is desired.
*/
boolean PR_CALLBACK
fill_input_buffer (j_decompress_ptr jd)
{
decoder_source_mgr *src = (decoder_source_mgr *)jd->src;
unsigned char *new_buffer = (unsigned char *)src->decoder->mBuffer;
PRUint32 new_buflen = src->decoder->mBufferLen;
PRUint32 bytesToSkip = src->decoder->mBytesToSkip;
switch(src->decoder->mFillState) {
case READING_BACK:
{
if (!new_buffer || new_buflen == 0)
return PR_FALSE; /* suspend */
src->decoder->mBufferLen = 0;
if (bytesToSkip != 0) {
if (bytesToSkip < new_buflen) {
/* All done skipping bytes; Return what's left. */
new_buffer += bytesToSkip;
new_buflen -= bytesToSkip;
src->decoder->mBytesToSkip = 0;
} else {
/* Still need to skip some more data in the future */
src->decoder->mBytesToSkip -= (size_t)new_buflen;
return PR_FALSE; /* suspend */
}
}
src->decoder->mBackBufferUnreadLen = src->pub.bytes_in_buffer;
src->pub.next_input_byte = new_buffer;
src->pub.bytes_in_buffer = (size_t)new_buflen;
src->decoder->mFillState = READING_NEW;
return PR_TRUE;
}
break;
case READING_NEW:
{
if (src->pub.next_input_byte != src->decoder->mBuffer) {
/* Backtrack data has been permanently consumed. */
src->decoder->mBackBufferUnreadLen = 0;
src->decoder->mBackBufferLen = 0;
}
/* Save remainder of netlib buffer in backtrack buffer */
PRUint32 new_backtrack_buflen = src->pub.bytes_in_buffer + src->decoder->mBackBufferLen;
/* Make sure backtrack buffer is big enough to hold new data. */
if (src->decoder->mBackBufferSize < new_backtrack_buflen) {
/* Round up to multiple of 16 bytes. */
PRUint32 roundup_buflen = ((new_backtrack_buflen + 15) >> 4) << 4;
if (src->decoder->mBackBufferSize) {
src->decoder->mBackBuffer =
(JOCTET *)PR_REALLOC(src->decoder->mBackBuffer, roundup_buflen);
} else {
src->decoder->mBackBuffer = (JOCTET*)PR_MALLOC(roundup_buflen);
}
/* Check for OOM */
if (!src->decoder->mBackBuffer) {
#if 0
j_common_ptr cinfo = (j_common_ptr)(&src->js->jd);
cinfo->err->msg_code = JERR_OUT_OF_MEMORY;
my_error_exit(cinfo);
#endif
}
src->decoder->mBackBufferSize = (size_t)roundup_buflen;
/* Check for malformed MARKER segment lengths. */
if (new_backtrack_buflen > MAX_JPEG_MARKER_LENGTH) {
my_error_exit((j_common_ptr)(&src->decoder->mInfo));
}
}
/* Copy remainder of netlib buffer into backtrack buffer. */
nsCRT::memmove(src->decoder->mBackBuffer + src->decoder->mBackBufferLen,
src->pub.next_input_byte,
src->pub.bytes_in_buffer);
/* Point to start of data to be rescanned. */
src->pub.next_input_byte = src->decoder->mBackBuffer + src->decoder->mBackBufferLen - src->decoder->mBackBufferUnreadLen;
src->pub.bytes_in_buffer += src->decoder->mBackBufferUnreadLen;
src->decoder->mBackBufferLen = (size_t)new_backtrack_buflen;
src->decoder->mFillState = READING_BACK;
return PR_FALSE;
}
break;
}
return PR_FALSE;
}
/******************************************************************************/
/* data source manager method */
/*
* Terminate source --- called by jpeg_finish_decompress() after all
* data has been read to clean up JPEG source manager. NOT called by
* jpeg_abort() or jpeg_destroy().
*/
void PR_CALLBACK
term_source (j_decompress_ptr jd)
{
decoder_source_mgr *src = (decoder_source_mgr *)jd->src;
if (src->decoder->mObserver) {
src->decoder->mObserver->OnStopFrame(nsnull, nsnull, src->decoder->mFrame);
src->decoder->mObserver->OnStopContainer(nsnull, nsnull, src->decoder->mImage);
src->decoder->mObserver->OnStopDecode(nsnull, nsnull, NS_OK, nsnull);
}
/* No work necessary here */
}

View File

@@ -0,0 +1,121 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#ifndef nsJPEGDecoder_h__
#define nsJPEGDecoder_h__
#include "imgIDecoder.h"
#include "nsCOMPtr.h"
#include "imgIContainer.h"
#include "gfxIImageFrame.h"
#include "imgIDecoderObserver.h"
#include "imgIRequest.h"
#include "nsIInputStream.h"
#include "nsIPipe.h"
extern "C" {
#include "jpeglib.h"
}
#include <setjmp.h>
#define NS_JPEGDECODER_CID \
{ /* 5871a422-1dd2-11b2-ab3f-e2e56be5da9c */ \
0x5871a422, \
0x1dd2, \
0x11b2, \
{0xab, 0x3f, 0xe2, 0xe5, 0x6b, 0xe5, 0xda, 0x9c} \
}
typedef struct {
struct jpeg_error_mgr pub; /* "public" fields for IJG library*/
jmp_buf setjmp_buffer; /* For handling catastropic errors */
} decoder_error_mgr;
typedef enum {
JPEG_HEADER, /* Reading JFIF headers */
JPEG_START_DECOMPRESS,
JPEG_DECOMPRESS_PROGRESSIVE, /* Output progressive pixels */
JPEG_DECOMPRESS_SEQUENTIAL, /* Output sequential pixels */
JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT,
JPEG_DONE,
JPEG_SINK_NON_JPEG_TRAILER, /* Some image files have a */
/* non-JPEG trailer */
JPEG_ERROR
} jstate;
class nsJPEGDecoder : public imgIDecoder
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMGIDECODER
NS_DECL_NSIOUTPUTSTREAM
nsJPEGDecoder();
virtual ~nsJPEGDecoder();
PRBool FillInput(j_decompress_ptr jd);
PRUint32 mBytesToSkip;
protected:
int OutputScanlines(int num_scanlines);
public:
nsCOMPtr<imgIContainer> mImage;
nsCOMPtr<gfxIImageFrame> mFrame;
nsCOMPtr<imgIRequest> mRequest;
nsCOMPtr<imgIDecoderObserver> mObserver;
struct jpeg_decompress_struct mInfo;
decoder_error_mgr mErr;
jstate mState;
JSAMPARRAY mSamples;
JSAMPARRAY mSamples3;
PRUint8* mRGBPadRow;
PRUint32 mRGBPadRowLength;
PRInt32 mCompletedPasses;
PRInt32 mPasses;
int mFillState;
JOCTET *mBuffer;
PRUint32 mBufferLen; // amount of data currently in mBuffer
PRUint32 mBufferSize; // size in bytes what mBuffer was created with
JOCTET *mBackBuffer;
PRUint32 mBackBufferLen; // Offset of end of active backtrack data
PRUint32 mBackBufferSize; // size in bytes what mBackBuffer was created with
PRUint32 mBackBufferUnreadLen; // amount of data currently in mBackBuffer
};
#endif // nsJPEGDecoder_h__

View File

@@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsJPEGDecoder.h"
// objects that just require generic constructors
NS_GENERIC_FACTORY_CONSTRUCTOR(nsJPEGDecoder)
static nsModuleComponentInfo components[] =
{
{ "ppm decoder",
NS_JPEGDECODER_CID,
"@mozilla.org/image/decoder;2?type=image/jpeg",
nsJPEGDecoderConstructor, },
};
NS_IMPL_NSGETMODULE("nsJPEGDecoderModule", components)

View File

@@ -0,0 +1,16 @@
?Release@nsJPEGDecoder@@UAGKXZ ; 172
?AddRef@nsJPEGDecoder@@UAGKXZ ; 172
?fill_input_buffer@@YAEPAUjpeg_decompress_struct@@@Z ; 126
?skip_input_data@@YAXPAUjpeg_decompress_struct@@J@Z ; 109
?WriteFrom@nsJPEGDecoder@@UAGIPAVnsIInputStream@@IPAI@Z ; 106
?OutputScanlines@nsJPEGDecoder@@IAEHH@Z ; 93
?init_source@@YAXPAUjpeg_decompress_struct@@@Z ; 86
??1nsJPEGDecoder@@UAE@XZ ; 86
?Close@nsJPEGDecoder@@UAGIXZ ; 86
?term_source@@YAXPAUjpeg_decompress_struct@@@Z ; 86
?Init@nsJPEGDecoder@@UAGIPAVimgIRequest@@@Z ; 86
??0nsJPEGDecoder@@QAE@XZ ; 86
?Flush@nsJPEGDecoder@@UAGIXZ ; 86
?QueryInterface@nsJPEGDecoder@@UAGIABUnsID@@PAPAX@Z ; 86
??_EnsJPEGDecoder@@UAEPAXI@Z ; 86
_NSGetModule ; 1

View File

@@ -0,0 +1,26 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH=..\..\..
DIRS = ppm gif png jpeg
!include $(DEPTH)\config\rules.mak

View File

@@ -0,0 +1,42 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = imgpng
LIBRARY_NAME = imgpng
IS_COMPONENT = 1
REQUIRES = xpcom necko layout png gfx2 imglib2
CPPSRCS = nsPNGDecoder.cpp nsPNGFactory.cpp
EXTRA_DSO_LDOPTS = $(PNG_LIBS) $(ZLIB_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,53 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Stuart Parmenter <pavlov@netscape.com>
#
DEPTH=..\..\..\..
include <$(DEPTH)/config/config.mak>
MODULE = imgpng
LIBRARY_NAME = imgpng
DLL = $(OBJDIR)\$(LIBRARY_NAME).dll
MAKE_OBJ_TYPE = DLL
OBJS = \
.\$(OBJDIR)\nsPNGDecoder.obj \
.\$(OBJDIR)\nsPNGFactory.obj \
$(NULL)
LLIBS=\
$(LIBNSPR) \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\png.lib \
$(DIST)\lib\zlib.lib \
$(DIST)\lib\gkgfxwin.lib \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(LIBRARY_NAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(LIBRARY_NAME).lib $(DIST)\lib
clobber::
rm -f $(DIST)\bin\components\$(LIBRARY_NAME).dll
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,553 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*
*/
#include "nsPNGDecoder.h"
#include "nsIInputStream.h"
#include "nspr.h"
#include "nsIComponentManager.h"
#include "png.h"
#include "nsIStreamObserver.h"
#include "nsRect.h"
#include "nsMemory.h"
#include "imgIContainerObserver.h"
// XXX we need to be sure to fire onStopDecode messages to mObserver in error cases.
NS_IMPL_ISUPPORTS2(nsPNGDecoder, imgIDecoder, nsIOutputStream)
nsPNGDecoder::nsPNGDecoder()
{
NS_INIT_ISUPPORTS();
mPNG = nsnull;
mInfo = nsnull;
colorLine = 0;
alphaLine = 0;
interlacebuf = 0;
}
nsPNGDecoder::~nsPNGDecoder()
{
if (colorLine)
nsMemory::Free(colorLine);
if (alphaLine)
nsMemory::Free(alphaLine);
if (interlacebuf)
nsMemory::Free(interlacebuf);
}
/** imgIDecoder methods **/
/* void init (in imgIRequest aRequest); */
NS_IMETHODIMP nsPNGDecoder::Init(imgIRequest *aRequest)
{
mRequest = aRequest;
mObserver = do_QueryInterface(aRequest); // we're holding 2 strong refs to the request.
aRequest->GetImage(getter_AddRefs(mImage));
/* do png init stuff */
/* Initialize the container's source image header. */
/* Always decode to 24 bit pixdepth */
mPNG = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL,
NULL);
if (!mPNG) {
return NS_ERROR_FAILURE;
}
mInfo = png_create_info_struct(mPNG);
if (!mInfo) {
png_destroy_read_struct(&mPNG, NULL, NULL);
return NS_ERROR_FAILURE;
}
/* use ic as libpng "progressive pointer" (retrieve in callbacks) */
png_set_progressive_read_fn(mPNG, NS_STATIC_CAST(png_voidp, this), nsPNGDecoder::info_callback, nsPNGDecoder::row_callback, nsPNGDecoder::end_callback);
return NS_OK;
}
/* readonly attribute imgIRequest request; */
NS_IMETHODIMP nsPNGDecoder::GetRequest(imgIRequest * *aRequest)
{
*aRequest = mRequest;
NS_ADDREF(*aRequest);
return NS_OK;
}
/** nsIOutputStream methods **/
/* void close (); */
NS_IMETHODIMP nsPNGDecoder::Close()
{
if (mPNG)
png_destroy_read_struct(&mPNG, mInfo ? &mInfo : NULL, NULL);
return NS_OK;
}
/* void flush (); */
NS_IMETHODIMP nsPNGDecoder::Flush()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* unsigned long write (in string buf, in unsigned long count); */
NS_IMETHODIMP nsPNGDecoder::Write(const char *buf, PRUint32 count, PRUint32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
static NS_METHOD ReadDataOut(nsIInputStream* in,
void* closure,
const char* fromRawSegment,
PRUint32 toOffset,
PRUint32 count,
PRUint32 *writeCount)
{
nsPNGDecoder *decoder = NS_STATIC_CAST(nsPNGDecoder*, closure);
// we need to do the setjmp here otherwise bad things will happen
if (setjmp(decoder->mPNG->jmpbuf)) {
png_destroy_read_struct(&decoder->mPNG, &decoder->mInfo, NULL);
// is this NS_ERROR_FAILURE enough?
decoder->mRequest->Cancel(NS_BINDING_ABORTED); // XXX is this the correct error ?
return NS_ERROR_FAILURE;
}
*writeCount = decoder->ProcessData((unsigned char*)fromRawSegment, count);
return NS_OK;
}
PRUint32 nsPNGDecoder::ProcessData(unsigned char *data, PRUint32 count)
{
png_process_data(mPNG, mInfo, data, count);
return count; // we always consume all the data
}
/* unsigned long writeFrom (in nsIInputStream inStr, in unsigned long count); */
NS_IMETHODIMP nsPNGDecoder::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval)
{
// PRUint32 sourceOffset = *_retval;
inStr->ReadSegments(ReadDataOut, this, count, _retval);
return NS_OK;
}
/* [noscript] unsigned long writeSegments (in nsReadSegmentFun reader, in voidPtr closure, in unsigned long count); */
NS_IMETHODIMP nsPNGDecoder::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute boolean nonBlocking; */
NS_IMETHODIMP nsPNGDecoder::GetNonBlocking(PRBool *aNonBlocking)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsPNGDecoder::SetNonBlocking(PRBool aNonBlocking)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute nsIOutputStreamObserver observer; */
NS_IMETHODIMP nsPNGDecoder::GetObserver(nsIOutputStreamObserver * *aObserver)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsPNGDecoder::SetObserver(nsIOutputStreamObserver * aObserver)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
void
nsPNGDecoder::info_callback(png_structp png_ptr, png_infop info_ptr)
{
/* int number_passes; NOT USED */
png_uint_32 width, height;
int bit_depth, color_type, interlace_type, compression_type, filter_type;
int channels;
double LUT_exponent, CRT_exponent = 2.2, display_exponent, aGamma;
png_bytep trans=NULL;
int num_trans =0;
/* always decode to 24-bit RGB or 32-bit RGBA */
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, &compression_type, &filter_type);
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL);
png_set_expand(png_ptr);
}
if (bit_depth == 16)
png_set_strip_16(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
#ifdef XP_PC
// windows likes BGR
png_set_bgr(png_ptr);
#endif
/* set up gamma correction for Mac, Unix and (Win32 and everything else)
* using educated guesses for display-system exponents; do preferences
* later */
#if defined(XP_MAC)
LUT_exponent = 1.8 / 2.61;
#elif defined(XP_UNIX)
# if defined(__sgi)
LUT_exponent = 1.0 / 1.7; /* typical default for SGI console */
# elif defined(NeXT)
LUT_exponent = 1.0 / 2.2; /* typical default for NeXT cube */
# else
LUT_exponent = 1.0; /* default for most other Unix workstations */
# endif
#else
LUT_exponent = 1.0; /* virtually all PCs and most other systems */
#endif
/* (alternatively, could check for SCREEN_GAMMA environment variable) */
display_exponent = LUT_exponent * CRT_exponent;
if (png_get_gAMA(png_ptr, info_ptr, &aGamma))
png_set_gamma(png_ptr, display_exponent, aGamma);
else
png_set_gamma(png_ptr, display_exponent, 0.45455);
/* let libpng expand interlaced images */
if (interlace_type == PNG_INTERLACE_ADAM7) {
/* number_passes = */
png_set_interlace_handling(png_ptr);
}
/* now all of those things we set above are used to update various struct
* members and whatnot, after which we can get channels, rowbytes, etc. */
png_read_update_info(png_ptr, info_ptr);
channels = png_get_channels(png_ptr, info_ptr);
PR_ASSERT(channels == 3 || channels == 4);
/*---------------------------------------------------------------*/
/* copy PNG info into imagelib structs (formerly png_set_dims()) */
/*---------------------------------------------------------------*/
PRInt32 alpha_bits = 1;
if (channels > 3) {
/* check if alpha is coming from a tRNS chunk and is binary */
if (num_trans) {
/* if it's not a indexed color image, tRNS means binary */
if (color_type == PNG_COLOR_TYPE_PALETTE) {
for (int i=0; i<num_trans; i++) {
if ((trans[i] != 0) && (trans[i] != 255)) {
alpha_bits = 8;
break;
}
}
}
} else {
alpha_bits = 8;
}
}
nsPNGDecoder *decoder = NS_STATIC_CAST(nsPNGDecoder*, png_get_progressive_ptr(png_ptr));
if (decoder->mObserver)
decoder->mObserver->OnStartDecode(nsnull, nsnull);
// since the png is only 1 frame, initalize the container to the width and height of the frame
decoder->mImage->Init(width, height, decoder->mObserver);
if (decoder->mObserver)
decoder->mObserver->OnStartContainer(nsnull, nsnull, decoder->mImage);
decoder->mFrame = do_CreateInstance("@mozilla.org/gfx/image/frame;2");
#if 0
// XXX should we longjmp to png_ptr->jumpbuf here if we failed?
if (!decoder->mFrame)
return NS_ERROR_FAILURE;
#endif
gfx_format format;
if (channels == 3) {
format = gfxIFormats::RGB;
} else if (channels > 3) {
if (alpha_bits == 8) {
decoder->mImage->GetPreferredAlphaChannelFormat(&format);
} else if (alpha_bits == 1) {
format = gfxIFormats::RGB_A1;
}
}
#ifdef XP_PC
// XXX this works...
format += 1; // RGB to BGR
#endif
// then initalize the frame and append it to the container
decoder->mFrame->Init(0, 0, width, height, format);
decoder->mImage->AppendFrame(decoder->mFrame);
if (decoder->mObserver)
decoder->mObserver->OnStartFrame(nsnull, nsnull, decoder->mFrame);
PRUint32 bpr, abpr;
decoder->mFrame->GetImageBytesPerRow(&bpr);
decoder->mFrame->GetAlphaBytesPerRow(&abpr);
decoder->colorLine = (PRUint8 *)nsMemory::Alloc(bpr);
if (channels > 3)
decoder->alphaLine = (PRUint8 *)nsMemory::Alloc(abpr);
if (interlace_type == PNG_INTERLACE_ADAM7) {
decoder->interlacebuf = (PRUint8 *)nsMemory::Alloc(channels*width*height);
decoder->ibpr = channels*width;
if (!decoder->interlacebuf) {
// return NS_ERROR_FAILURE;
}
}
return;
}
void
nsPNGDecoder::row_callback(png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass)
{
/* libpng comments:
*
* this function is called for every row in the image. If the
* image is interlacing, and you turned on the interlace handler,
* this function will be called for every row in every pass.
* Some of these rows will not be changed from the previous pass.
* When the row is not changed, the new_row variable will be NULL.
* The rows and passes are called in order, so you don't really
* need the row_num and pass, but I'm supplying them because it
* may make your life easier.
*
* For the non-NULL rows of interlaced images, you must call
* png_progressive_combine_row() passing in the row and the
* old row. You can call this function for NULL rows (it will
* just return) and for non-interlaced images (it just does the
* memcpy for you) if it will make the code easier. Thus, you
* can just do this for all cases:
*
* png_progressive_combine_row(png_ptr, old_row, new_row);
*
* where old_row is what was displayed for previous rows. Note
* that the first pass (pass == 0 really) will completely cover
* the old row, so the rows do not have to be initialized. After
* the first pass (and only for interlaced images), you will have
* to pass the current row, and the function will combine the
* old row and the new row.
*/
nsPNGDecoder *decoder = NS_STATIC_CAST(nsPNGDecoder*, png_get_progressive_ptr(png_ptr));
PRUint32 bpr, abpr;
decoder->mFrame->GetImageBytesPerRow(&bpr);
decoder->mFrame->GetAlphaBytesPerRow(&abpr);
png_bytep line;
if (decoder->interlacebuf) {
line = decoder->interlacebuf+(row_num*decoder->ibpr);
png_progressive_combine_row(png_ptr, line, new_row);
}
else
line = new_row;
if (new_row) {
nscoord width;
decoder->mFrame->GetWidth(&width);
PRUint32 iwidth = width;
gfx_format format;
decoder->mFrame->GetFormat(&format);
PRUint8 *aptr, *cptr;
// The mac specific ifdefs in the code below are there to make sure we
// always fill in 4 byte pixels right now, which is what the mac always
// allocates for its pixel buffers in true color mode. This will change
// when we start storing images with color palettes when they don't need
// true color support (GIFs).
switch (format) {
case gfxIFormats::RGB:
case gfxIFormats::BGR:
#ifdef XP_MAC
cptr = decoder->colorLine;
for (PRUint32 x=0; x<iwidth; x++) {
*cptr++ = 0;
*cptr++ = *line++;
*cptr++ = *line++;
*cptr++ = *line++;
}
decoder->mFrame->SetImageData(decoder->colorLine, bpr, row_num*bpr);
#else
decoder->mFrame->SetImageData((PRUint8*)line, bpr, row_num*bpr);
#endif
break;
case gfxIFormats::RGB_A1:
case gfxIFormats::BGR_A1:
{
cptr = decoder->colorLine;
aptr = decoder->alphaLine;
memset(aptr, 0, abpr);
for (PRUint32 x=0; x<iwidth; x++) {
#ifdef XP_MAC
*cptr++ = 0;
#endif
*cptr++ = *line++;
*cptr++ = *line++;
*cptr++ = *line++;
if (*line++) {
aptr[x>>3] |= 1<<(7-x&0x7);
}
}
decoder->mFrame->SetImageData(decoder->colorLine, bpr, row_num*bpr);
decoder->mFrame->SetAlphaData(decoder->alphaLine, abpr, row_num*abpr);
}
break;
case gfxIFormats::RGB_A8:
case gfxIFormats::BGR_A8:
{
cptr = decoder->colorLine;
aptr = decoder->alphaLine;
for (PRUint32 x=0; x<iwidth; x++) {
#ifdef XP_MAC
*cptr++ = 0;
#endif
*cptr++ = *line++;
*cptr++ = *line++;
*cptr++ = *line++;
*aptr++ = *line++;
}
decoder->mFrame->SetImageData(decoder->colorLine, bpr, row_num*bpr);
decoder->mFrame->SetAlphaData(decoder->alphaLine, abpr, row_num*abpr);
}
break;
case gfxIFormats::RGBA:
case gfxIFormats::BGRA:
#ifdef XP_MAC
{
cptr = decoder->colorLine;
aptr = decoder->alphaLine;
for (PRUint32 x=0; x<iwidth; x++) {
*cptr++ = 0;
*cptr++ = *line++;
*cptr++ = *line++;
*cptr++ = *line++;
*aptr++ = *line++;
}
decoder->mFrame->SetImageData(decoder->colorLine, bpr, row_num*bpr);
decoder->mFrame->SetAlphaData(decoder->alphaLine, abpr, row_num*abpr);
}
#else
decoder->mFrame->SetImageData(line, bpr, row_num*bpr);
#endif
break;
}
nsRect r(0, row_num, width, 1);
decoder->mObserver->OnDataAvailable(nsnull, nsnull, decoder->mFrame, &r);
}
}
void
nsPNGDecoder::end_callback(png_structp png_ptr, png_infop info_ptr)
{
/* libpng comments:
*
* this function is called when the whole image has been read,
* including any chunks after the image (up to and including
* the IEND). You will usually have the same info chunk as you
* had in the header, although some data may have been added
* to the comments and time fields.
*
* Most people won't do much here, perhaps setting a flag that
* marks the image as finished.
*/
nsPNGDecoder *decoder = NS_STATIC_CAST(nsPNGDecoder*, png_get_progressive_ptr(png_ptr));
if (decoder->mObserver) {
decoder->mObserver->OnStopFrame(nsnull, nsnull, decoder->mFrame);
decoder->mObserver->OnStopContainer(nsnull, nsnull, decoder->mImage);
decoder->mObserver->OnStopDecode(nsnull, nsnull, NS_OK, nsnull);
}
}

View File

@@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#ifndef nsPNGDecoder_h__
#define nsPNGDecoder_h__
#include "imgIDecoder.h"
#include "imgIContainer.h"
#include "imgIDecoderObserver.h"
#include "gfxIImageFrame.h"
#include "imgIRequest.h"
#include "nsCOMPtr.h"
#include "png.h"
#define NS_PNGDECODER_CID \
{ /* 36fa00c2-1dd2-11b2-be07-d16eeb4c50ed */ \
0x36fa00c2, \
0x1dd2, \
0x11b2, \
{0xbe, 0x07, 0xd1, 0x6e, 0xeb, 0x4c, 0x50, 0xed} \
}
class nsPNGDecoder : public imgIDecoder
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMGIDECODER
NS_DECL_NSIOUTPUTSTREAM
nsPNGDecoder();
virtual ~nsPNGDecoder();
PR_STATIC_CALLBACK(void)
info_callback(png_structp png_ptr, png_infop info_ptr);
PR_STATIC_CALLBACK(void)
row_callback(png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass);
PR_STATIC_CALLBACK(void)
end_callback(png_structp png_ptr, png_infop info_ptr);
inline PRUint32 ProcessData(unsigned char *data, PRUint32 count);
public:
nsCOMPtr<imgIContainer> mImage;
nsCOMPtr<gfxIImageFrame> mFrame;
nsCOMPtr<imgIRequest> mRequest;
nsCOMPtr<imgIDecoderObserver> mObserver; // this is just qi'd from mRequest for speed
png_structp mPNG;
png_infop mInfo;
PRUint8 *colorLine, *alphaLine;
PRUint8 *interlacebuf;
PRUint32 ibpr;
};
#endif // nsPNGDecoder_h__

View File

@@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsPNGDecoder.h"
// objects that just require generic constructors
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPNGDecoder)
static nsModuleComponentInfo components[] =
{
{ "PNG decoder",
NS_PNGDECODER_CID,
"@mozilla.org/image/decoder;2?type=image/png",
nsPNGDecoderConstructor, },
{ "PNG decoder",
NS_PNGDECODER_CID,
"@mozilla.org/image/decoder;2?type=image/x-png",
nsPNGDecoderConstructor, },
};
NS_IMPL_NSGETMODULE("nsPNGDecoderModule", components)

View File

@@ -0,0 +1,42 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = imgppm
LIBRARY_NAME = imgppm
IS_COMPONENT = 1
REQUIRES = xpcom layout necko gfx2 imglib2
CPPSRCS = nsPPMDecoder.cpp nsPPMFactory.cpp
EXTRA_DSO_LDOPTS = \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,51 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Stuart Parmenter <pavlov@netscape.com>
#
DEPTH=..\..\..\..
include <$(DEPTH)/config/config.mak>
MODULE = imgppm
LIBRARY_NAME = imgppm
DLL = $(OBJDIR)\$(LIBRARY_NAME).dll
MAKE_OBJ_TYPE = DLL
OBJS = \
.\$(OBJDIR)\nsPPMDecoder.obj \
.\$(OBJDIR)\nsPPMFactory.obj \
$(NULL)
LLIBS=\
$(LIBNSPR) \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\gkgfxwin.lib \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(LIBRARY_NAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(LIBRARY_NAME).lib $(DIST)\lib
clobber::
rm -f $(DIST)\bin\components\$(LIBRARY_NAME).dll
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,305 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*
*/
#include "nsPPMDecoder.h"
#include "nsIInputStream.h"
#include "imgIContainer.h"
#include "imgIContainerObserver.h"
#include "nspr.h"
#include "nsIComponentManager.h"
#include "nsRect.h"
NS_IMPL_ISUPPORTS2(nsPPMDecoder, imgIDecoder, nsIOutputStream)
nsPPMDecoder::nsPPMDecoder()
{
NS_INIT_ISUPPORTS();
mDataReceived = 0;
mDataWritten = 0;
mDataLeft = 0;
mPrevData = nsnull;
}
nsPPMDecoder::~nsPPMDecoder()
{
}
/** imgIDecoder methods **/
/* void init (in imgIRequest aRequest); */
NS_IMETHODIMP nsPPMDecoder::Init(imgIRequest *aRequest)
{
mRequest = aRequest;
mObserver = do_QueryInterface(aRequest); // we're holding 2 strong refs to the request.
aRequest->GetImage(getter_AddRefs(mImage));
mFrame = do_CreateInstance("@mozilla.org/gfx/image/frame;2");
if (!mFrame)
return NS_ERROR_FAILURE;
return NS_OK;
}
/* readonly attribute imgIRequest request; */
NS_IMETHODIMP nsPPMDecoder::GetRequest(imgIRequest * *aRequest)
{
*aRequest = mRequest;
NS_ADDREF(*aRequest);
return NS_OK;
}
/** nsIOutputStream methods **/
/* void close (); */
NS_IMETHODIMP nsPPMDecoder::Close()
{
if (mObserver) {
mObserver->OnStopFrame(nsnull, nsnull, mFrame);
mObserver->OnStopContainer(nsnull, nsnull, mImage);
mObserver->OnStopDecode(nsnull, nsnull, NS_OK, nsnull);
}
return NS_OK;
}
/* void flush (); */
NS_IMETHODIMP nsPPMDecoder::Flush()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* unsigned long write (in string buf, in unsigned long count); */
NS_IMETHODIMP nsPPMDecoder::Write(const char *buf, PRUint32 count, PRUint32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
static char *__itoa(int n)
{
char *s;
int i, j, sign, tmp;
/* check sign and convert to positive to stringify numbers */
if ( (sign = n) < 0)
n = -n;
i = 0;
s = (char*) malloc(sizeof(char));
/* grow string as needed to add numbers from powers of 10
* down till none left
*/
do
{
s = (char*) realloc(s, (i+1)*sizeof(char));
s[i++] = n % 10 + '0'; /* '0' or 30 is where ASCII numbers start */
s[i] = '\0';
}
while( (n /= 10) > 0);
/* tack on minus sign if we found earlier that this was negative */
if (sign < 0)
{
s = (char*) realloc(s, (i+1)*sizeof(char));
s[i++] = '-';
}
s[i] = '\0';
/* pop numbers (and sign) off of string to push back into right direction */
for (i = 0, j = strlen(s) - 1; i < j; i++, j--)
{
tmp = s[i];
s[i] = s[j];
s[j] = tmp;
}
return s;
}
/* unsigned long writeFrom (in nsIInputStream inStr, in unsigned long count); */
NS_IMETHODIMP nsPPMDecoder::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval)
{
nsresult rv;
char *buf = (char *)PR_Malloc(count + mDataLeft);
if (!buf)
return NS_ERROR_OUT_OF_MEMORY; /* we couldn't allocate the object */
// read the data from the input stram...
PRUint32 readLen;
rv = inStr->Read(buf+mDataLeft, count, &readLen);
PRUint32 dataLen = readLen + mDataLeft;
if (mPrevData) {
strncpy(buf, mPrevData, mDataLeft);
PR_Free(mPrevData);
mPrevData = nsnull;
mDataLeft = 0;
}
char *data = buf;
if (NS_FAILED(rv)) return rv;
if (mDataReceived == 0) {
mObserver->OnStartDecode(nsnull, nsnull);
// Check the magic number
char type;
if ((sscanf(data, "P%c\n", &type) !=1) || (type != '6')) {
return NS_ERROR_FAILURE;
}
int i = 3;
data += i;
#if 0
// XXX
// Ignore comments
while ((input = fgetc(f)) == '#')
fgets(junk, 512, f);
ungetc(input, f);
#endif
// Read size
int w, h, mcv;
if (sscanf(data, "%d %d\n%d\n", &w, &h, &mcv) != 3) {
return NS_ERROR_FAILURE;
}
char *ws = __itoa(w), *hs = __itoa(h), *mcvs = __itoa(mcv);
int j = strlen(ws) + strlen(hs) + strlen(mcvs) + 3;
data += j;
// free(ws);
// free(hs);
// free(mcvs);
readLen -= i + j;
dataLen = readLen; // since this is the first pass, we don't have any data waiting that we need to keep track of
mImage->Init(w, h, mObserver);
if (mObserver)
mObserver->OnStartContainer(nsnull, nsnull, mImage);
mFrame->Init(0, 0, w, h, gfxIFormats::RGB);
mImage->AppendFrame(mFrame);
if (mObserver)
mObserver->OnStartFrame(nsnull, nsnull, mFrame);
}
PRUint32 bpr;
nscoord width;
mFrame->GetImageBytesPerRow(&bpr);
mFrame->GetWidth(&width);
// XXX ceil?
PRUint32 real_bpr = width * 3;
PRUint32 i = 0;
PRUint32 rownum = mDataWritten / real_bpr; // XXX this better not have a decimal
PRUint32 wroteLen = 0;
if (readLen > real_bpr) {
do {
PRUint8 *line = (PRUint8*)data + i*real_bpr;
mFrame->SetImageData(line, real_bpr, (rownum++)*bpr);
nsRect r(0, rownum, width, 1);
mObserver->OnDataAvailable(nsnull, nsnull, mFrame, &r);
wroteLen += real_bpr ;
i++;
} while(dataLen >= real_bpr * (i+1));
}
mDataReceived += readLen; // don't double count previous data that is in 'dataLen'
mDataWritten += wroteLen;
PRUint32 dataLeft = dataLen - wroteLen;
if (dataLeft > 0) {
if (mPrevData) {
mPrevData = (char *)PR_Realloc(mPrevData, mDataLeft + dataLeft);
strncpy(mPrevData + mDataLeft, data+wroteLen, dataLeft);
mDataLeft += dataLeft;
} else {
mDataLeft = dataLeft;
mPrevData = (char *)PR_Malloc(mDataLeft);
strncpy(mPrevData, data+wroteLen, mDataLeft);
}
}
PR_FREEIF(buf);
return NS_OK;
}
/* [noscript] unsigned long writeSegments (in nsReadSegmentFun reader, in voidPtr closure, in unsigned long count); */
NS_IMETHODIMP nsPPMDecoder::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute boolean nonBlocking; */
NS_IMETHODIMP nsPPMDecoder::GetNonBlocking(PRBool *aNonBlocking)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsPPMDecoder::SetNonBlocking(PRBool aNonBlocking)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute nsIOutputStreamObserver observer; */
NS_IMETHODIMP nsPPMDecoder::GetObserver(nsIOutputStreamObserver * *aObserver)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsPPMDecoder::SetObserver(nsIOutputStreamObserver * aObserver)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@@ -0,0 +1,67 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#ifndef nsPPMDecoder_h__
#define nsPPMDecoder_h__
#include "imgIDecoder.h"
#include "nsCOMPtr.h"
#include "imgIContainer.h"
#include "imgIDecoderObserver.h"
#include "gfxIImageFrame.h"
#include "imgIRequest.h"
#define NS_PPMDECODER_CID \
{ /* e90bfa06-1dd1-11b2-8217-f38fe5d431a2 */ \
0xe90bfa06, \
0x1dd1, \
0x11b2, \
{0x82, 0x17, 0xf3, 0x8f, 0xe5, 0xd4, 0x31, 0xa2} \
}
class nsPPMDecoder : public imgIDecoder
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMGIDECODER
NS_DECL_NSIOUTPUTSTREAM
nsPPMDecoder();
virtual ~nsPPMDecoder();
private:
nsCOMPtr<imgIContainer> mImage;
nsCOMPtr<gfxIImageFrame> mFrame;
nsCOMPtr<imgIRequest> mRequest;
nsCOMPtr<imgIDecoderObserver> mObserver; // this is just qi'd from mRequest for speed
PRUint32 mDataReceived;
PRUint32 mDataWritten;
PRUint32 mDataLeft;
char *mPrevData;
};
#endif // nsPPMDecoder_h__

View File

@@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsPPMDecoder.h"
// objects that just require generic constructors
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPPMDecoder)
static nsModuleComponentInfo components[] =
{
{ "ppm decoder",
NS_PPMDECODER_CID,
"@mozilla.org/image/decoder;2?type=image/x-portable-pixmap",
nsPPMDecoderConstructor, },
};
NS_IMPL_NSGETMODULE("nsPPMDecoderModule", components)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,25 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH=..\..
DIRS = public src decoders
!include $(DEPTH)\config\rules.mak

View File

@@ -0,0 +1,111 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "prlog.h"
#include "nsString.h"
#if defined(PR_LOGGING)
extern PRLogModuleInfo *gImgLog;
class LogScope {
public:
LogScope(PRLogModuleInfo *aLog, void *from, const nsAReadableCString &fn) :
mLog(aLog), mFrom(from), mFunc(fn)
{
PR_LOG(mLog, PR_LOG_DEBUG, ("[this=%p] %s {ENTER}\n",
mFrom, mFunc.get()));
}
/* const char * constructor */
LogScope(PRLogModuleInfo *aLog, void *from, const nsAReadableCString &fn,
const nsLiteralCString &paramName, const char *paramValue) :
mLog(aLog), mFrom(from), mFunc(fn)
{
PR_LOG(mLog, PR_LOG_DEBUG, ("[this=%p] %s (%s=\"%s\") {ENTER}\n",
mFrom, mFunc.get(),
paramName.get(),
paramValue));
}
/* void ptr constructor */
LogScope(PRLogModuleInfo *aLog, void *from, const nsAReadableCString &fn,
const nsLiteralCString &paramName, const void *paramValue) :
mLog(aLog), mFrom(from), mFunc(fn)
{
PR_LOG(mLog, PR_LOG_DEBUG, ("[this=%p] %s (%s=%p) {ENTER}\n",
mFrom, mFunc.get(),
paramName.get(),
paramValue));
}
/* PRInt32 constructor */
LogScope(PRLogModuleInfo *aLog, void *from, const nsAReadableCString &fn,
const nsLiteralCString &paramName, PRInt32 paramValue) :
mLog(aLog), mFrom(from), mFunc(fn)
{
PR_LOG(mLog, PR_LOG_DEBUG, ("[this=%p] %s (%s=\"%d\") {ENTER}\n",
mFrom, mFunc.get(),
paramName.get(),
paramValue));
}
/* PRUint32 constructor */
LogScope(PRLogModuleInfo *aLog, void *from, const nsAReadableCString &fn,
const nsLiteralCString &paramName, PRUint32 paramValue) :
mLog(aLog), mFrom(from), mFunc(fn)
{
PR_LOG(mLog, PR_LOG_DEBUG, ("[this=%p] %s (%s=\"%d\") {ENTER}\n",
mFrom, mFunc.get(),
paramName.get(),
paramValue));
}
~LogScope() {
PR_LOG(mLog, PR_LOG_DEBUG, ("[this=%p] %s {EXIT}\n",
mFrom, mFunc.get()));
}
private:
PRLogModuleInfo *mLog;
void *mFrom;
nsCAutoString mFunc;
};
#define LOG_SCOPE(l, s) \
LogScope LOG_SCOPE_TMP_VAR ##__LINE__ (l, \
NS_STATIC_CAST(void *, this), \
NS_LITERAL_CSTRING(s))
#define LOG_SCOPE_WITH_PARAM(l, s, pn, pv) \
LogScope LOG_SCOPE_TMP_VAR ##__LINE__ (l, \
NS_STATIC_CAST(void *, this), \
NS_LITERAL_CSTRING(s), \
NS_LITERAL_CSTRING(pn), pv)
#else
#define LOG_SCOPE(l, s)
#define LOG_SCOPE_WITH_PARAM(l, s, pn, pv)
#endif

View File

@@ -0,0 +1 @@
ImageLogging.h

View File

@@ -0,0 +1,6 @@
imgIContainer.idl
imgIContainerObserver.idl
imgIDecoder.idl
imgIDecoderObserver.idl
imgILoader.idl
imgIRequest.idl

View File

@@ -0,0 +1,41 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = imglib2
EXPORTS = ImageLogging.h
XPIDLSRCS = imgIContainer.idl \
imgIContainerObserver.idl \
imgIDecoder.idl \
imgIDecoderObserver.idl \
imgILoader.idl \
imgIRequest.idl
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,109 @@
/** -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsISupports.idl"
#include "gfxtypes.idl"
#include "gfxIFormats.idl"
interface gfxIImageFrame;
interface nsIEnumerator;
interface imgIContainerObserver;
/**
* gfxIImageContainer interface
*
* @author Stuart Parmenter <pavlov@netscape.com>
* @version 0.1
* @see "gfx2"
*/
[scriptable, uuid(5e8405a4-1dd2-11b2-8385-bc8e3446cad3)]
interface imgIContainer : nsISupports
{
/**
* Create a new \a aWidth x \a aHeight sized image container.
*
* @param aWidth The width of the container in which all the
* gfxIImageFrame children will fit.
* @param aHeight The height of the container in which all the
* gfxIImageFrame children will fit.
* @param aObserver Observer to send animation notifications to.
*/
void init(in nscoord aWidth,
in nscoord aHeight,
in imgIContainerObserver aObserver);
/* this should probably be on the device context (or equiv) */
readonly attribute gfx_format preferredAlphaChannelFormat;
/**
* The width of the container rectangle.
*/
readonly attribute nscoord width;
/**
* The height of the container rectangle.
*/
readonly attribute nscoord height;
/**
* Get the current frame that would be drawn if the image was to be drawn now
*/
readonly attribute gfxIImageFrame currentFrame;
readonly attribute unsigned long numFrames;
gfxIImageFrame getFrameAt(in unsigned long index);
/**
* Adds \a item to the end of the list of frames.
* @param item frame to add.
*/
void appendFrame(in gfxIImageFrame item);
void removeFrame(in gfxIImageFrame item);
/* notification when the current frame is done decoding */
void endFrameDecode(in unsigned long framenumber, in unsigned long timeout);
/* notification that the entire image has been decoded */
void decodingComplete();
nsIEnumerator enumerate();
void clear();
void startAnimation();
void stopAnimation();
/* animation stuff */
/**
* number of times to loop the image.
* @note -1 means forever.
*/
attribute long loopCount;
};

View File

@@ -0,0 +1,46 @@
/** -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsISupports.idl"
#include "gfxtypes.idl"
%{C++
#include "nsRect.h"
%}
interface imgIContainer;
interface gfxIImageFrame;
/**
* imgIContainerObserver interface
*
* @author Stuart Parmenter <pavlov@netscape.com>
* @version 0.1
*/
[uuid(153f1518-1dd2-11b2-b9cd-b16eb63e0471)]
interface imgIContainerObserver : nsISupports
{
[noscript] void frameChanged(in imgIContainer aContainer, in nsISupports aCX,
in gfxIImageFrame aFrame, in nsRect aDirtyRect);
};

View File

@@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsISupports.idl"
#include "nsIOutputStream.idl"
#include "gfxtypes.idl"
interface imgIRequest;
/**
* imgIDecoder interface
*
* @author Stuart Parmenter <pavlov@netscape.com>
* @version 0.1
* @see imagelib2
*/
[scriptable, uuid(9eebf43a-1dd1-11b2-953e-f1782f4cbad3)]
interface imgIDecoder : nsIOutputStream
{
/**
* Initalize an image decoder.
* @param aRequest the request that owns the decoder.
*
* @note The decode should QI \a aRequest to an imgIDecoderObserver
* and should send decoder notifications to the request.
* The decoder should always pass NULL as the first two parameters to
* all of the imgIDecoderObserver APIs.
*/
void init(in imgIRequest aRequest);
/// allows access to the nsIImage we have to put bits in to.
readonly attribute imgIRequest request;
};

View File

@@ -0,0 +1,80 @@
/** -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "imgIContainerObserver.idl"
interface imgIRequest;
interface imgIContainer;
interface gfxIImageFrame;
%{C++
#include "nsRect.h"
%}
/**
* imgIDecoderObserver interface
*
* @author Stuart Parmenter <pavlov@netscape.com>
* @version 0.1
* @see imagelib2
*/
[scriptable, uuid(350163d2-1dd2-11b2-9e69-89959ecec1f3)]
interface imgIDecoderObserver : imgIContainerObserver
{
/**
* called as soon as the image begins getting decoded
*/
void onStartDecode(in imgIRequest aRequest, in nsISupports cx);
/**
* called once the image has been inited and therefore has a width and height
*/
void onStartContainer(in imgIRequest aRequest, in nsISupports cx, in imgIContainer aContainer);
/**
* called when each frame is created
*/
void onStartFrame(in imgIRequest aRequest, in nsISupports cx, in gfxIImageFrame aFrame);
/**
* called when some part of the frame has new data in it
*/
[noscript] void onDataAvailable(in imgIRequest aRequest, in nsISupports cx, in gfxIImageFrame aFrame, [const] in nsRect aRect);
/**
* called when a frame is finished decoding
*/
void onStopFrame(in imgIRequest aRequest, in nsISupports cx, in gfxIImageFrame aFrame);
/**
* probably not needed. called right before onStopDecode
*/
void onStopContainer(in imgIRequest aRequest, in nsISupports cx, in imgIContainer aContainer);
/**
* called when the decoder is dying off
*/
void onStopDecode(in imgIRequest aRequest, in nsISupports cx,
in nsresult status, in wstring statusArg);
};

View File

@@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsISupports.idl"
#include "gfxtypes.idl"
interface imgIDecoderObserver;
interface imgIRequest;
interface nsIChannel;
interface nsILoadGroup;
interface nsIStreamListener;
interface nsIURI;
interface nsISimpleEnumerator;
/**
* imgILoader interface
*
* @author Stuart Parmenter <pavlov@netscape.com>
* @version 0.1
* @see imagelib2
*/
[scriptable, uuid(4c8cf1e0-1dd2-11b2-aff9-c51cdbfcb6da)]
interface imgILoader : nsISupports
{
/**
* Start the load and decode of an image.
* @param uri the URI to load
* @param aObserver the observer
* @param cx some random data
*/
imgIRequest loadImage(in nsIURI uri, in nsILoadGroup aLoadGroup, in imgIDecoderObserver aObserver, in nsISupports cx);
/**
* Start the load and decode of an image.
* @param uri the URI to load
* @param aObserver the observer
* @param cx some random data
*/
imgIRequest loadImageWithChannel(in nsIChannel aChannel, in imgIDecoderObserver aObserver, in nsISupports cx, out nsIStreamListener aListener);
};

View File

@@ -0,0 +1,80 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "nsISupports.idl"
#include "nsIRequest.idl"
interface imgIContainer;
interface imgIDecoderObserver;
interface nsIURI;
/**
* imgIRequest interface
*
* @author Stuart Parmenter <pavlov@netscape.com>
* @version 0.1
* @see imagelib2
*/
[scriptable, uuid(ccf705f6-1dd1-11b2-82ef-e18eccf7f7ec)]
interface imgIRequest : nsIRequest
{
/**
* the image container...
* @return the image object associated with the request.
* @attention NEED DOCS
*/
readonly attribute imgIContainer image;
/**
* Bits set in the return value from imageStatus
* @name statusflags
*/
//@{
const long STATUS_NONE = 0x0;
const long STATUS_SIZE_AVAILABLE = 0x1;
const long STATUS_LOAD_COMPLETE = 0x2;
const long STATUS_ERROR = 0x4;
//@}
/**
* something
* @attention NEED DOCS
*/
readonly attribute unsigned long imageStatus;
readonly attribute nsIURI URI;
readonly attribute imgIDecoderObserver decoderObserver;
};
%{C++
/**
* imagelib specific nsresult success and error codes
*/
#define NS_IMAGELIB_SUCCESS_LOAD_FINISHED NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_IMGLIB, 0)
#define NS_IMAGELIB_ERROR_FAILURE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_IMGLIB, 5)
#define NS_IMAGELIB_ERROR_NO_DECODER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_IMGLIB, 6)
%}

View File

@@ -0,0 +1,43 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Stuart Parmenter <pavlov@netscape.com>
#
DEPTH = ..\..\..
include <$(DEPTH)/config/config.mak>
MODULE = imglib2
XPIDL_MODULE = imglib2
EXPORTS = ImageLogging.h
XPIDLSRCS = \
.\imgIContainer.idl \
.\imgIContainerObserver.idl \
.\imgIDecoder.idl \
.\imgIDecoderObserver.idl \
.\imgILoader.idl \
.\imgIRequest.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,146 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include "DummyChannel.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
NS_IMPL_ISUPPORTS1(DummyChannel, nsIChannel)
DummyChannel::DummyChannel(imgIRequest *aRequest, nsILoadGroup *aLoadGroup) :
mRequest(aRequest),
mLoadGroup(aLoadGroup),
mLoadFlags(nsIChannel::LOAD_NORMAL)
{
NS_INIT_ISUPPORTS();
/* member initializers and constructor code */
}
DummyChannel::~DummyChannel()
{
/* destructor code */
}
/* attribute nsIURI originalURI; */
NS_IMETHODIMP DummyChannel::GetOriginalURI(nsIURI * *aOriginalURI)
{
return mRequest->GetURI(aOriginalURI);
}
NS_IMETHODIMP DummyChannel::SetOriginalURI(nsIURI * aOriginalURI)
{
return NS_ERROR_FAILURE;
}
/* attribute nsIURI URI; */
NS_IMETHODIMP DummyChannel::GetURI(nsIURI * *aURI)
{
return mRequest->GetURI(aURI);
}
NS_IMETHODIMP DummyChannel::SetURI(nsIURI * aURI)
{
return NS_ERROR_FAILURE;
}
/* attribute nsISupports owner; */
NS_IMETHODIMP DummyChannel::GetOwner(nsISupports * *aOwner)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DummyChannel::SetOwner(nsISupports * aOwner)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute nsILoadGroup loadGroup; */
NS_IMETHODIMP DummyChannel::GetLoadGroup(nsILoadGroup * *aLoadGroup)
{
*aLoadGroup = mLoadGroup;
NS_IF_ADDREF(*aLoadGroup);
return NS_OK;
}
NS_IMETHODIMP DummyChannel::SetLoadGroup(nsILoadGroup * aLoadGroup)
{
return NS_ERROR_FAILURE;
}
/* attribute nsLoadFlags loadAttributes; */
NS_IMETHODIMP DummyChannel::GetLoadAttributes(nsLoadFlags *aLoadAttributes)
{
*aLoadAttributes = mLoadFlags;
return NS_OK;
}
NS_IMETHODIMP DummyChannel::SetLoadAttributes(nsLoadFlags aLoadAttributes)
{
mLoadFlags = aLoadAttributes;
return NS_OK;
}
/* attribute nsIInterfaceRequestor notificationCallbacks; */
NS_IMETHODIMP DummyChannel::GetNotificationCallbacks(nsIInterfaceRequestor * *aNotificationCallbacks)
{
return NS_OK;
}
NS_IMETHODIMP DummyChannel::SetNotificationCallbacks(nsIInterfaceRequestor * aNotificationCallbacks)
{
return NS_OK;
}
/* readonly attribute nsISupports securityInfo; */
NS_IMETHODIMP DummyChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute string contentType; */
NS_IMETHODIMP DummyChannel::GetContentType(char * *aContentType)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DummyChannel::SetContentType(const char * aContentType)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute long contentLength; */
NS_IMETHODIMP DummyChannel::GetContentLength(PRInt32 *aContentLength)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DummyChannel::SetContentLength(PRInt32 aContentLength)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* nsIInputStream open (); */
NS_IMETHODIMP DummyChannel::Open(nsIInputStream **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void asyncOpen (in nsIStreamListener listener, in nsISupports ctxt); */
NS_IMETHODIMP DummyChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

Some files were not shown because too many files have changed in this diff Show More