Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
nsInstallTrigger Class Reference

#include <nsInstallTrigger.h>

Inheritance diagram for nsInstallTrigger:
Inheritance graph
[legend]
Collaboration diagram for nsInstallTrigger:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsInstallTrigger ()
virtual ~nsInstallTrigger ()
NS_DECL_ISUPPORTS
NS_DECL_NSICONTENTHANDLER
NS_IMETHOD 
GetScriptObject (nsIScriptContext *aContext, void **aScriptObject)
NS_IMETHOD SetScriptObject (void *aScriptObject)
NS_IMETHOD UpdateEnabled (nsIScriptGlobalObject *aGlobalObject, PRBool aUseWhitelist, PRBool *aReturn)
NS_IMETHOD Install (nsIScriptGlobalObject *aGlobalObject, nsXPITriggerInfo *aInfo, PRBool *aReturn)
NS_IMETHOD InstallChrome (nsIScriptGlobalObject *aGlobalObject, PRUint32 aType, nsXPITriggerItem *aItem, PRBool *aReturn)
NS_IMETHOD StartSoftwareUpdate (nsIScriptGlobalObject *aGlobalObject, const nsString &aURL, PRInt32 aFlags, PRInt32 *aReturn)
NS_IMETHOD CompareVersion (const nsString &aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32 *aReturn)
NS_IMETHOD CompareVersion (const nsString &aRegName, const nsString &aVersion, PRInt32 *aReturn)
NS_IMETHOD CompareVersion (const nsString &aRegName, nsIDOMInstallVersion *aVersion, PRInt32 *aReturn)
NS_IMETHOD GetVersion (const nsString &component, nsString &version)
void handleContent (in string aContentType, in nsIInterfaceRequestor aWindowContext, in nsIRequest aRequest)
 Tells the content handler to take over handling the content.

Static Public Member Functions

static const nsIIDIID ()

Private Member Functions

PRBool AllowInstall (nsIURI *aLaunchURI)

Private Attributes

voidmScriptObject

Detailed Description

Definition at line 34 of file nsInstallTrigger.h.


Constructor & Destructor Documentation

Definition at line 74 of file nsInstallTrigger.cpp.

{
    mScriptObject   = nsnull;

    // make sure all the SoftwareUpdate initialization has happened
    nsCOMPtr<nsISoftwareUpdate> svc (do_GetService(NS_IXPINSTALLCOMPONENT_CONTRACTID));
}

Here is the call graph for this function:

Definition at line 82 of file nsInstallTrigger.cpp.

{
}

Member Function Documentation

PRBool nsInstallTrigger::AllowInstall ( nsIURI aLaunchURI) [private]

Definition at line 316 of file nsInstallTrigger.cpp.

{
    // Check the global setting.
    PRBool xpiEnabled = PR_FALSE;
    nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
    if ( !prefBranch)
    {
        return PR_TRUE; // no pref service in native install, it's OK
    }

    prefBranch->GetBoolPref( XPINSTALL_ENABLE_PREF, &xpiEnabled);
    if ( !xpiEnabled )
    {
        // globally turned off
        return PR_FALSE;
    }


    // Check permissions for the launching host if we have one
    nsCOMPtr<nsIPermissionManager> permissionMgr =
                            do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);

    if ( permissionMgr && aLaunchURI )
    {
        PRBool isChrome = PR_FALSE;
        PRBool isFile = PR_FALSE;
        aLaunchURI->SchemeIs( "chrome", &isChrome );
        aLaunchURI->SchemeIs( "file", &isFile );

        // file: and chrome: don't need whitelisted hosts
        if ( !isChrome && !isFile )
        {
            // check prefs for permission updates before testing URI
            updatePermissions( XPINSTALL_WHITELIST_ADD,
                               nsIPermissionManager::ALLOW_ACTION,
                               permissionMgr, prefBranch );
            updatePermissions( XPINSTALL_WHITELIST_ADD_103,
                               nsIPermissionManager::ALLOW_ACTION,
                               permissionMgr, prefBranch );
            updatePermissions( XPINSTALL_BLACKLIST_ADD,
                               nsIPermissionManager::DENY_ACTION,
                               permissionMgr, prefBranch );

            PRBool requireWhitelist = PR_TRUE;
            prefBranch->GetBoolPref( XPINSTALL_WHITELIST_REQUIRED, &requireWhitelist );

            PRUint32 permission = nsIPermissionManager::UNKNOWN_ACTION;
            permissionMgr->TestPermission( aLaunchURI, XPI_PERMISSION, &permission );

            if ( permission == nsIPermissionManager::DENY_ACTION )
            {
                xpiEnabled = PR_FALSE;
            }
            else if ( requireWhitelist &&
                      permission != nsIPermissionManager::ALLOW_ACTION )
            {
                xpiEnabled = PR_FALSE;
            }
        }
    }

    return xpiEnabled;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsInstallTrigger::CompareVersion ( const nsString aRegName,
PRInt32  aMajor,
PRInt32  aMinor,
PRInt32  aRelease,
PRInt32  aBuild,
PRInt32 aReturn 
)

Definition at line 516 of file nsInstallTrigger.cpp.

{
    nsInstallVersion inVersion;
    inVersion.Init(aMajor, aMinor, aRelease, aBuild);

    return CompareVersion(aRegName, &inVersion, aReturn);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsInstallTrigger::CompareVersion ( const nsString aRegName,
const nsString aVersion,
PRInt32 aReturn 
)

Definition at line 525 of file nsInstallTrigger.cpp.

{
    nsInstallVersion inVersion;
    inVersion.Init(aVersion);

    return CompareVersion(aRegName, &inVersion, aReturn);
}

Here is the call graph for this function:

Definition at line 534 of file nsInstallTrigger.cpp.

{
    *aReturn = NOT_FOUND;  // assume failure.

    VERSION              cVersion;
    NS_ConvertUCS2toUTF8 regName(aRegName);
    REGERR               status;
    nsInstallVersion     regNameVersion;

    status = VR_GetVersion( NS_CONST_CAST(char *, regName.get()), &cVersion );
    if ( status == REGERR_OK )
    {
        // we found the version
        if ( VR_ValidateComponent( NS_CONST_CAST(char *, regName.get()) ) != REGERR_NOFILE )
        {
            // and the installed file was not missing:  do the compare
            regNameVersion.Init(cVersion.major,
                                cVersion.minor,
                                cVersion.release,
                                cVersion.build);

            regNameVersion.CompareTo( aVersion, aReturn );
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

NS_DECL_ISUPPORTS NS_DECL_NSICONTENTHANDLER NS_IMETHOD nsInstallTrigger::GetScriptObject ( nsIScriptContext aContext,
void **  aScriptObject 
)

Definition at line 563 of file nsInstallTrigger.cpp.

{
    VERSION              cVersion;
    NS_ConvertUCS2toUTF8 regName(component);
    REGERR               status;

    status = VR_GetVersion( NS_CONST_CAST(char *, regName.get()), &cVersion );

    version.Truncate();

    /* if we got the version */
    // XXX fix the right way after PR3 or RTM
    // if ( status == REGERR_OK && VR_ValidateComponent( tempCString ) == REGERR_OK)
    if ( status == REGERR_OK )
    {
        nsInstallVersion regNameVersion;

        regNameVersion.Init(cVersion.major,
                            cVersion.minor,
                            cVersion.release,
                            cVersion.build);

        regNameVersion.ToString(version);
    }

    return NS_OK;
}

Here is the call graph for this function:

void nsIContentHandler::handleContent ( in string  aContentType,
in nsIInterfaceRequestor  aWindowContext,
in nsIRequest  aRequest 
) [inherited]

Tells the content handler to take over handling the content.

If this function succeeds, the URI Loader will leave this request alone, ignoring progress notifications. Failure of this method will cause the request to be cancelled, unless the error code is NS_ERROR_WONT_HANDLE_CONTENT (see below).

Parameters:
aWindowContextWindow context, used to get things like the current nsIDOMWindow for this request. May be null.
aContentTypeThe content type of aRequest
aRequestA request whose content type is already known.
Exceptions:
NS_ERROR_WONT_HANDLE_CONTENTIndicates that this handler does not want to handle this content. A different way for handling this content should be tried.
static const nsIID& nsInstallTrigger::IID ( ) [inline, static]

Definition at line 39 of file nsInstallTrigger.h.

NS_IMETHODIMP nsInstallTrigger::Install ( nsIScriptGlobalObject aGlobalObject,
nsXPITriggerInfo aInfo,
PRBool aReturn 
)

Definition at line 417 of file nsInstallTrigger.cpp.

{
    NS_ASSERTION(aReturn, "Invalid pointer arg");
    *aReturn = PR_FALSE;

    nsresult rv;
    nsXPInstallManager *mgr = new nsXPInstallManager();
    if (mgr)
    {
        // The Install manager will delete itself when done
        rv = mgr->InitManager( aGlobalObject, aTrigger, 0 );
        if (NS_SUCCEEDED(rv))
            *aReturn = PR_TRUE;
    }
    else
    {
        delete aTrigger;
        rv = NS_ERROR_OUT_OF_MEMORY;
    }


    return rv;
}

Here is the call graph for this function:

NS_IMETHODIMP nsInstallTrigger::InstallChrome ( nsIScriptGlobalObject aGlobalObject,
PRUint32  aType,
nsXPITriggerItem aItem,
PRBool aReturn 
)

Definition at line 443 of file nsInstallTrigger.cpp.

{
    NS_ENSURE_ARG_POINTER(aReturn);
    NS_ENSURE_ARG_POINTER(aItem);
    *aReturn = PR_FALSE;


    // The Install manager will delete itself when done, once we've called
    // InitManager. Before then **WE** must delete it
    nsresult rv = NS_ERROR_OUT_OF_MEMORY;
    nsXPInstallManager *mgr = new nsXPInstallManager();
    if (mgr)
    {
        nsXPITriggerInfo* trigger = new nsXPITriggerInfo();
        if ( trigger )
        {
            trigger->Add( aItem );

            // The Install manager will delete itself when done
            rv = mgr->InitManager( aGlobalObject, trigger, aType );
            *aReturn = PR_TRUE;
        }
        else
        {
            rv = NS_ERROR_OUT_OF_MEMORY;
            delete mgr;
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 112 of file nsInstallTrigger.cpp.

{
  mScriptObject = aScriptObject;
  return NS_OK;
}

Definition at line 476 of file nsInstallTrigger.cpp.

{
    nsresult rv = NS_ERROR_OUT_OF_MEMORY;
    *aReturn = PR_FALSE;

    // The Install manager will delete itself when done, once we've called
    // InitManager. Before then **WE** must delete it
    nsXPInstallManager *mgr = new nsXPInstallManager();
    if (mgr)
    {
        nsXPITriggerInfo* trigger = new nsXPITriggerInfo();
        if ( trigger )
        {
            nsXPITriggerItem* item = new nsXPITriggerItem(0,aURL.get(),nsnull);
            if (item)
            {
                trigger->Add( item );
                // The Install manager will delete itself when done
                rv = mgr->InitManager(aGlobalObject, trigger, 0 );
                *aReturn = PR_TRUE;
            }
            else
            {
                rv = NS_ERROR_OUT_OF_MEMORY;
                delete trigger;
                delete mgr;
            }
        }
        else
        {
            rv = NS_ERROR_OUT_OF_MEMORY;
            delete mgr;
        }
    }

    return rv;
}

Here is the call graph for this function:

NS_IMETHODIMP nsInstallTrigger::UpdateEnabled ( nsIScriptGlobalObject aGlobalObject,
PRBool  aUseWhitelist,
PRBool aReturn 
)

Definition at line 382 of file nsInstallTrigger.cpp.

{
    // disallow unless we successfully find otherwise
    *aReturn = PR_FALSE;

    if (!aUseWhitelist)
    {
        // simple global pref check
        nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
        if (prefBranch)
            prefBranch->GetBoolPref( XPINSTALL_ENABLE_PREF, aReturn);
    }
    else
    {
        NS_ENSURE_ARG_POINTER(aGlobalObject);

        // find the current site
        nsCOMPtr<nsIDOMDocument> domdoc;
        nsCOMPtr<nsIDOMWindow> window(do_QueryInterface(aGlobalObject));
        if ( window )
        {
            window->GetDocument(getter_AddRefs(domdoc));
            nsCOMPtr<nsIDocument> doc(do_QueryInterface(domdoc));
            if ( doc )
            {
                *aReturn = AllowInstall( doc->GetDocumentURI() );
            }
        }
    }

    return NS_OK;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 62 of file nsInstallTrigger.h.


The documentation for this class was generated from the following files: