Adding nsIContentHandler to XPInstall so that we can handle mime types. This

allows us to click on a xpinstall link and have the install happen.

I also changed the windows wizard test application to use explict paths.  This
should have been checked in with the rest of the nsIFile/xpInstall stuff.  You
may have to adjust these paths manually.
This commit is contained in:
dougt%netscape.com 2000-05-08 05:12:35 +00:00
Родитель 835b7a3525
Коммит af2653ff5f
5 изменённых файлов: 67 добавлений и 130 удалений

Просмотреть файл

@ -35,7 +35,7 @@
class nsIDOMInstallTriggerGlobal : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMINSTALLTRIGGERGLOBAL_IID; return iid; }
static const nsIID& GetIID() { static nsIID iid = NS_IDOMINSTALLTRIGGERGLOBAL_IID; return iid; }
enum {
MAJOR_DIFF = 4,
MINOR_DIFF = 3,

Просмотреть файл

@ -40,6 +40,10 @@
#include "VerReg.h"
#include "nsIContentHandler.h"
#include "nsIChannel.h"
#include "nsIURI.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
@ -47,9 +51,8 @@ static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIInstallTrigger_IID, NS_IDOMINSTALLTRIGGERGLOBAL_IID);
static NS_DEFINE_IID(kIInstallTrigger_CID, NS_SoftwareUpdateInstallTrigger_CID);
static NS_DEFINE_IID(kPrefsIID, NS_IPREF_IID);
static NS_DEFINE_IID(kPrefsCID, NS_PREF_CID);
nsInstallTrigger::nsInstallTrigger()
{
@ -61,42 +64,11 @@ nsInstallTrigger::~nsInstallTrigger()
{
}
NS_IMETHODIMP
nsInstallTrigger::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kIScriptObjectOwnerIID))
{
*aInstancePtr = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kIInstallTrigger_IID) )
{
*aInstancePtr = (void*) ((nsIDOMInstallTriggerGlobal*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsInstallTrigger)
NS_IMPL_RELEASE(nsInstallTrigger)
NS_IMPL_THREADSAFE_ISUPPORTS3 (nsInstallTrigger,
nsIScriptObjectOwner,
nsIDOMInstallTriggerGlobal,
nsIContentHandler);
NS_IMETHODIMP
@ -129,8 +101,42 @@ nsInstallTrigger::SetScriptObject(void *aScriptObject)
return NS_OK;
}
static NS_DEFINE_IID(kPrefsIID, NS_IPREF_IID);
static NS_DEFINE_IID(kPrefsCID, NS_PREF_CID);
NS_IMETHODIMP
nsInstallTrigger::HandleContent(const char * aContentType,
const char * aCommand,
const char * aWindowTarget,
nsISupports* aWindowContext,
nsIChannel * aChannel)
{
nsresult rv = NS_OK;
if (!aChannel) return NS_ERROR_NULL_POINTER;
if (nsCRT::strcasecmp(aContentType, "application/x-xpinstall") == 0) {
nsCOMPtr<nsIURI> uri;
rv = aChannel->GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv;
if (uri) {
char* spec;
uri->GetSpec(&spec);
if (!spec)
return NS_ERROR_NULL_POINTER;
PRBool value;
rv = StartSoftwareUpdate(NS_ConvertASCIItoUCS2(spec), 0, &value);
nsAllocator::Free(spec);
if (NS_SUCCEEDED(rv) && value)
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsInstallTrigger::UpdateEnabled(PRBool* aReturn)
@ -479,50 +485,3 @@ nsInstallTrigger::GetVersion(const nsString& component, nsString& version)
return NS_OK;
}
#if 0
// this will take a nsIURI, and create a temporary file. If it is local, we just us it.
void
nsInstallTrigger::CreateTempFileFromURL(const nsString& aURL, nsString& tempFileString)
{
// Checking to see if the url is local
if ( aURL.EqualsIgnoreCase("file:/", 6) )
{
tempFileString.AssignWithConversion( NS_STATIC_CAST(const char*, nsNSPRPath(nsFileURL(aURL))) );
}
else
{
nsSpecialSystemDirectory tempFile(nsSpecialSystemDirectory::OS_TemporaryDirectory);
PRInt32 result = aURL.RFindChar('/');
if (result != -1)
{
nsString jarName;
aURL.Right(jarName, (aURL.Length() - result) );
PRInt32 argOffset = jarName.RFindChar('?');
if (argOffset != -1)
{
// we need to remove ? and everything after it
jarName.Truncate(argOffset);
}
tempFile += jarName;
}
else
{
tempFile += "xpinstall.jar";
}
tempFile.MakeUnique();
tempFileString.AssignWithConversion( NS_STATIC_CAST(const char*, nsNSPRPath( nsFilePath(tempFile) )) );
}
}
#endif

Просмотреть файл

@ -14,14 +14,17 @@
#include "nsSoftwareUpdate.h"
#include "nsXPITriggerInfo.h"
#include "nsIContentHandler.h"
#define CHROME_SKIN 1
#define CHROME_LOCALE 2
#define CHROME_SAFEMAX CHROME_LOCALE
#define CHROME_CONTENT 4
#define CHROME_ALL 7
class nsInstallTrigger: public nsIScriptObjectOwner, public nsIDOMInstallTriggerGlobal
class nsInstallTrigger: public nsIScriptObjectOwner,
public nsIDOMInstallTriggerGlobal,
public nsIContentHandler
{
public:
static const nsIID& IID() { static nsIID iid = NS_SoftwareUpdateInstallTrigger_CID; return iid; }
@ -30,6 +33,7 @@ class nsInstallTrigger: public nsIScriptObjectOwner, public nsIDOMInstallTrigger
virtual ~nsInstallTrigger();
NS_DECL_ISUPPORTS
NS_DECL_NSICONTENTHANDLER
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);

Просмотреть файл

@ -68,6 +68,8 @@
#include "nsProxiedService.h"
#include "nsIChromeRegistry.h"
#include "nsCURILoader.h"
extern "C" void RunChromeInstallOnThread(void *data);
////////////////////////////////////////////////////////////////////////////////
@ -183,45 +185,11 @@ nsSoftwareUpdate::~nsSoftwareUpdate()
//------------------------------------------------------------------------
// nsISupports implementation
//------------------------------------------------------------------------
NS_IMPL_THREADSAFE_ADDREF( nsSoftwareUpdate );
NS_IMPL_THREADSAFE_RELEASE( nsSoftwareUpdate );
NS_IMETHODIMP
nsSoftwareUpdate::QueryInterface( REFNSIID anIID, void **anInstancePtr )
{
nsresult rv = NS_OK;
/* Check for place to return result. */
if ( !anInstancePtr )
{
rv = NS_ERROR_NULL_POINTER;
}
else
{
/* Check for IIDs we support and cast this appropriately. */
if ( anIID.Equals( NS_GET_IID(nsISoftwareUpdate) ) )
*anInstancePtr = (void*) ( (nsISoftwareUpdate*)this );
else if ( anIID.Equals( NS_GET_IID(nsIAppShellComponent) ) )
*anInstancePtr = (void*) ( (nsIAppShellComponent*)this );
else if (anIID.Equals( NS_GET_IID(nsPIXPIStubHook) ) )
*anInstancePtr = (void*) ( (nsPIXPIStubHook*)this );
else if ( anIID.Equals( kISupportsIID ) )
*anInstancePtr = (void*) ( (nsISupports*) (nsISoftwareUpdate*) this );
else
{
/* Not an interface we support. */
*anInstancePtr = 0;
rv = NS_NOINTERFACE;
}
}
if (NS_SUCCEEDED(rv))
NS_ADDREF_THIS();
return rv;
}
NS_IMPL_THREADSAFE_ISUPPORTS3(nsSoftwareUpdate,
nsISoftwareUpdate,
nsIAppShellComponent,
nsPIXPIStubHook);
NS_IMETHODIMP
nsSoftwareUpdate::Initialize( nsIAppShellService *anAppShell, nsICmdLineService *aCmdLineService )
@ -707,6 +675,12 @@ static nsModuleComponentInfo components[] =
nsInstallVersionConstructor
},
{ "XPInstall Content Handler",
NS_SoftwareUpdateInstallTrigger_CID,
NS_CONTENT_HANDLER_PROGID_PREFIX"application/x-xpinstall",
nsInstallTriggerConstructor
},
#if NOTIFICATION_ENABLED
{ "XPInstall Update Notifier",
NS_XPI_UPDATE_NOTIFIER_CID,

Просмотреть файл

@ -368,8 +368,8 @@ int main(void)
char szBuf[MAX_BUF];
char szAppName[MAX_BUF];
char szAppPath[MAX_BUF];
char *listArchive[] = {"test1.xpi",
"test2.xpi",
char *listArchive[] = {"e:\\cmonkey\\mozilla\\dist\\win32_d.obj\\bin\\test1.xpi",
"e:\\cmonkey\\mozilla\\dist\\win32_d.obj\\bin\\test2.xpi",
"\0"};
if(GetModuleFileName(NULL, szBuf, sizeof(szBuf)) == 0L)